Assign string to UITextView
I am trying to load text into a textview. This seems simple enough:
box.text = @"hello";
NSLog(@"Box.text contains: %@", box.text);
The problem is that this NSLog just keeps printing null. (I have IBOutlet UITextView *box declared.) I imagine that since box.text is null, that's why nothing is actually showing up in the UITextVi开发者_JAVA百科ew either.
Anyone know what's going wrong?
Thanks a lot!
If you're calling box.text
from your controller's init
method, your IBOutlet hasn't been loaded from the nib file yet – so box
is still pointing to nil, and the text assignment is going nowhere. You'll need to wait until viewDidLoad
or later to successfully access the properties of your IBOutlet.
精彩评论