开发者

iOS3, iOS4, xibbed UIViewController and displaying data

I'm writing an app that will run on iOS3.0 and up.

The app has a custom UIViewController (say), which I'm instantiating from a .xib file. It's view comprises a single UILabel, which I've correctly declared and synthesized etc. in my custom UIViewController header and implementation files.

I'd like to set the text of this UILabel dynamically, and for it to be开发者_StackOverflow社区 shown to the user by the time my UIViewController appears. For sake of argument please assume the text setting method is expensive.

The catch is on iOS3.0 with my UIViewController at least, -(id)initWithNibName:(NSString *) aNibNameOrNil bundle:(NSBundle *) aNibBundleOrNil returns before -(void)viewDidLoad does, but on my iOS4.0 device it's the other way around. The text label can therefore be nil when I don't want it to be.

Thus, I don't know where I can set the text in such a way as to keep both iOS3.0 and iOS4.0 happy.

Any advice here?


Can you please explain how your label comes out to be nil?

If you have taken an outlet for the label, then in either case, in the - (void)viewDidLoad method it cannot be nil, provided the label outlet is properly connected in the xib file.

If you have not taken the label outlet and doing it by code, then instantiate the label again in - (void)viewDidLoad method and set its text right over there and then add it to the view controller's view.

For more information - read the - (void)viewDidLoad and - (id)initWithNibName:(NSString *)nibName bundle:(NSBundle *)nibBundle method in the UIViewController class reference

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜