开发者

iphone - view init issue

I have come across a strange behavior...

In class A, at the viewDidLoad method I do:

b = [[B alloc] initWithNibName:@"B" bundle:nil]; //init the B class (declared as B* b)
[b setText:@"ABCDDEEE"]; //change the text of a UITextView in b

note that b's view is not shown until a button is 开发者_开发百科pressed. However, when I press it and go to b's view, the text of the UITextView is still the "lorem ipsun" text

Once b's view is shown once, I can change the text.

Anyone know this issue and how to solve it??


That is expected behaviour. initWithNibNamedoes not guarantee complete initialization before viewDidLoad is called.


Create an NSString @property in B. Set that property when you load b--not the .text property of a UITextView, but an NSString data object in the view controller. Then in B's -(void)viewDidLoad, set the UITextView's text property with the string you set.

NIB elements don't necessarily exist when the parent view controller first instantiates a new view controller, but you can talk to data fields and then load that data into the view hierarchy members in -(void)viewDidLoad.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜