I'm having a lot of trouble with what seems like a very simple thing. I cannot update a UILabel programmatically from a Navigation-based iOS App. I don't want to use a button as this label is designed to report the status of an external system, and should update on launch. There is no need to make the user go though the extra step on touching the button if I don't have to.
The following is a somewhat exhaustive list of the steps I've taken. I'm sorry if some of this seems unnecessary, but in my experience even the smallest forgotten step can be the cause of the issue.
From a fresh Navigation-based App in Xcode here are the steps I'm taking:
- Replace UITableView with a generic UIView class
- Re-wire File's Owner's view outlet to the new UIView
- Add a UILabel to the center of the UIView, make the text centered, and leave the default text.
- Save and Exit Interface Builder
- RootViewController.h
#import
<UIKit>
@interface RootViewController : UIViewController { UILabel *myLabel; } @property (nonatomic, retain) IBOutlet UILabel *myLabel; @end - RootViewController.m
#import "RootViewController.h" @implementation RootViewController @synthesize myLabel; ...
- Removed TableView stuff from RootViewController.m
- Wire IBOutlet myLabel to the Label in RootViewController.xib
- Save and Exit Interface Builder
- tempNavAppAppDelegate.m
...
-
(BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { // Override point for customization after application launch.
// Add the navigation controller's view to the window and display. [self.window addSubview:navigationController.view]; [self.window makeKeyAndVisible];
RootViewController *rootViewCont = navigationController.visibleViewController; rootViewCont.myLabel.text = @"test"; NSLog(@"Label Text: %@", rootViewCont.myLabel.text);
return YES; } ... - Build/Run
The Label shows as "Label" not "test". And the log reports:tempNavApp[94186:207] Label Text: (null)
I've tried a number of different ways to get this done, but any help would be appreciated.