Can't affect UITextView content with initWithCoder
I'm trying to get a string displayed in my UITextView the moment the app is launched. I have a UIView and a UITextView in my interface, and one outlet, myText, which is connected to the UITextView. It doesn't seem to be working and I can't say why....
Here is the code in question:
MainView.h
#import <UIKit/UIKit.h>
#import <Foundation/Foundation.h>
@interface MainView : UIView {
IBOutlet UITextView *myText;
}
@end
MainView.m
@implementation MainView
-(id) initWithCoder:(NSCoder *)coder {
if ((self = [super initWithCoder:coder]) != nil)
{
NSLog(@"initWithCoder executed");
myText.text = @"Hello, World!";
}
return self;
}
@end
The NSLog() message is printed, so I assume that that myText.text is indeed set to @"Hello World", but this isn't reflected in my UITextView. Where is the hang up here? If it helps, this is a simplified version of my actual app, and when I put that same myText.text = @"Hello, World!"; into a method that responds to a button press, the ch开发者_如何学Goange is reflected in the text view.
Nib connections are not necessarily there in initWithCoder: — just because this object has been unfrozen doesn't mean everything else in the nib has been. You want awakeFromNib.
加载中,请稍侯......
精彩评论