我有以下代码:
@interface AXWindowController : NSWindowController {
IBOutlet NSTextField *text;
IBOutlet NSTextField *otherText;
}
- (void) setText: (NSString *)input;
- (void) setOtherText;
@end
@implementation AXWindowController
- (void) setText: (NSString *)input
{
[text setStringValue:input];
}
- (void) setOtherText
{
[otherText setStringValue:@"nag"];
}
@end
当我运行时:
1. [controller showWindow:nil];
2. [controller setText:@"lol"];
3. [controller setOtherText];
第 3 行正确执行,但第 2 行什么也不做。事实上,当我在执行第 2 行和第 3 行时查看 gdb 中的 text 和 otherText 时,会得到以下结果:
(gdb) p text
$1 = (NSTextField *) 0x0
(gdb) p otherText
$2 = (NSTextField *) 0x1385d1e0
怎么了?我不能将输入变量传递给 NSTextField 的 set 函数?当我更改 set 函数的参数时,为什么我的 NSTextField 变为空?