Search code examples
iphoneios4interface-builderuilabel

Adding and changing labels on the iPhone? (IOS4+)


I'm trying to write a "hello world" for iPhone 4. As this is my first attempt at iPhone app development, and my first experience with Objective C, please feel free to assume you need to teach me how to suck eggs on this one.

As my foundation, I started with the http://appsamuck.com/day1.html tutorial - but it's so far out of date I'm not going to get anywhere unless I de-construct the steps.

At this point I'm looking at the part where he tells you how to add a label to the display AND add the reference to the label.

Unfortunately it just doesn't seem to be fitting together properly.

Essentially, what I'd like the simulator to do when I run the "Built and Run" button is for the "MyLabel" to change to read "HERE"

When this all runs, there are no errors, but cdLabel.text is not changing to read "HERE".

I've got a photo of the basic GUI setup - and can post any other information needed.

the ViewController.h reads:

@interface MinutesToMidnightViewController : UIViewController {
     IBOutlet UILabel *cdLabel;
 }
 -(void)updateLabel;

the ViewController.m has the following function in it:

 -(void)updateLabel {
  cdLabel.text = [NSString: "HERE"];
 }

Finally - there's a photo of how I've set up the GUI bits in the interface designer:

If there's anyone who can connect the dot on this last bit I'd be so very grateful! (Also directions to IOS4 beginner's tutorials or open source APPS would be highly valued :)

Thanks! - A

UPDATE: In response to the question of when do I call updateLabel

I have the function

 - (void)applicationDidFinishLaunching:(UIApplication *)application {   
     [viewController updateLabel];
 }

built into my MinutesToMidnightAppDelegate.m file


Solution

  • Synthesize cdLabel in your .m, and set your label.text in viewDidLoad. Also, [NSString: "Here"] will not work. Just use cdLabel.text = @"HERE"; (Which is the same as: cdLabel.text = [NSString stringWithFormat:@"HERE"];