0
@interface TestViewController : NSViewController
@property (nonatomic, retain) IBOutlet NSTextField *myLabel;
- (IBAction)sendMessage:(NSButton *)sender;
@end
@implementation TestViewController
@synthesize myLabel = _myLabel;
- (id)init{
self = [super init];
if(self){
[self updateLabel];
}
return self;
}
- (IBAction)sendMessage:(NSButton *)sender {
[self updateLabel];
NSLog(@"Message sent");
}
- (void) updateLabel{
NSLog(@"Update!! %@");
[self.myLabel setStringValue:@"random text"];
}
@end
我想显示视图时更新的NSTextField,我把我的updateLabel
在init
日志我看到Update!!
中,但NSTextField
它不符合我的文字更新。 但是,当我按下按钮,调用相同updateLabel
NSTextField
更新。有人能帮我理解为什么它不能按预期工作吗?Objective-C的更新的NSTextField初始化
您是否尝试在init方法中放入一条日志语句以确保它被调用? – rdelmar 2012-07-27 02:22:48
我说'init'打印出来'NSLog(@“Update !!%@”);'但是文本中的字段是一样的 – Constantin 2012-07-27 02:24:40
对不起,错过了。这可能是因为在init方法中这样做在这个过程中为时尚早。你如何加载视图控制器的视图?你在实现loadView吗?如果是这样,请尝试将调用放入updateLabel中。 – rdelmar 2012-07-27 02:33:33