@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
的 at放在我init
看到的日志中,Update!!
但NSTextField
它没有用我的文本更新。但是当我按下调用相同的按钮时,它updateLabel
是NSTextField
更新的。有人可以帮我理解为什么它没有按预期工作吗?