How to change an interface button title from within ios code

1) Open your Nib file (.xib) for your view controller.

2) Click on the button that you want to be able to change the label for, and from the Utilities panel (Appears on the far right when you enable it in Xcode view) and go to the connections section.

3) You probably already have a connection (Touch Up Inside or something else) to some method in your File’s Owner (Your controller class). In order to be able to access the attributes of the button itself from within the class, we need to make a new Referencing Outlet to this button.

To create a new referencing outlet for this button, click inside the circle for “New Referencing Outlet” and drag (connect) to your controller’s header file. Give it a name, like myButton.

Congratulations! You can now access and potentially modify the attributes of your button from within your iOS program.

4) You can now make use of the following source code, to change the button title (when an action is hit, for example):

1
[myButton setTitle:"New Label" forState:UIControlStateNormal];

There are other UIControl states that you can use, but this was sufficient for me.

get current date time in iOS

This was copied directly from a blog post of Murat Yilmaz

1
2
3
4
5
6
7
8
9
10
11
NSCalendar *calendar = [[NSCalendar alloc] initWithCalendarIdentifier: NSGregorianCalendar];
NSCalendarUnit unitFlags = NSYearCalendarUnit | NSMonthCalendarUnitNSWeekCalendarUnit | NSDayCalendarUnit | NSHourCalendarUnit | NSMinuteCalendarUnit | NSSecondCalendarUnit;
NSDate *date = [NSDate date];
NSDateComponents *dateComponents = [calendar components:unitFlags fromDate:date];
NSInteger year = [dateComponents year];
NSInteger month = [dateComponents month];
NSInteger week = [dateComponents week];
NSInteger day = [dateComponents day];
NSInteger hour = [dateComponents hour];
NSInteger minute = [dateComponents minute];
NSInteger second = [dateComponents second];

How to add a framework to your project in xcode 4

When I googled for this, I got false information — so here is how you do it:


1) First click the Blue Xcode icon signifying your project on the lefthand navigation pane.


Confused? The highlighted thing:


1.png

2) Now look right, to the next pane. Make sure the project name under TARGETS is selected, not PROJECTS.


Looks like this:


2.png

3) Next pane on the right, you’ll see a few things at the top, “Summary”, “Info”, “Build Settings”, “Build Phases”, “Build Rules” … You want to click on Build Phases.


You will see a few expandable sections now.


4) Expand the section labeled Link Binary With Libraries


You should now be seeing something that looks like this:


3.png

5) Click the + button at the bottom-left of that Link Binary With Libraries section


Select the library you want, for example, AVFoundation.framework and click Add.


You’ll notice the library/framework has appeared in your navigation pane at the left.


You can go ahead and drag that into the Frameworks folder.


6) In order to utilize the framework, you will need to #import it into your source code.


For AVFoundation.framework, I simply put the following line in my main.m, right under the existing #import for UIKit



#import <AVFoundation/AVFoundation.h>



And that worked for me.

Upgraded to xcode 4 could not insert new outlet

Are you following along on Apple’s “Your First iOS Application” guide, found here ?


Did you upgrade to Xcode 4 mid way? Now when you try to create an outlet, and it says it “could not insert new outlet” in scary red letters; something about not know what class you are looking for.


But… my application builds! What the hell?


Confusing, yes, but this worked for me:


1) Go to your helloWorldAppDelegate.m file


2) You’ll see this code:



@synthesize myViewController;



or you might see

1
@synthesize myViewController=_myViewController;

3) If it is like the first example, change it to look like the 2nd one. If it is like the 2nd one, change it to look like the first.


4) Make sure the memory release is correct in your dealloc method at the bottom of the same file. If you changed the @synthesize to look like the 2nd example, make sure the release looks as such:

1
[_myViewController release];

And vice versa.


5) Build, simulate. If it works, try making the connection again from your nib file to your header file. At this point it worked for me.


Oddly enough, once it worked, I was able to reverse the changes in the helloWordAppDelegate.m file without any problems. Clearly this was just a bug in transitioning from Xcode 3 to Xcode 4.


Keep in mind that the two different ways of synthesizing that class variable is simply a matter of stylistic concern. In the earlier pages of the guide, it is explained that the underscore in _myViewController is to “remind you that you’re not supposed to access class variables directly “

Learning ios development for free

Learning iOS Development for Free

There are a lot of great lectures on learning iOS development on the iTunesU network free for download. But it’s slow going and I’d rather code than watch lectures about it.

This guy has a bunch of links and this is where I’ve started a few days ago with iOS.

mahipal:


“Can you recommend a good book for getting started with Objective-C?”


I get this question a lot, but there’s no need to spend any money or even to spend time digesting an entire book. I always point people to the Apple docs — the documentation is very modular and (mostly) very reliable.