views:

33

answers:

2

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??

+1  A: 

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

tob
is there a way to force it to load completely?
dkk
I don't think so.You could call `[b setText:]` and store the value in a member of your controller. Then set the value of the member in your view's `viewWillAppear` from the member.
tob
+1  A: 

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.

Dan Ray
That's exactly how I implemented it =)
dkk