我有以下代码:为什么只有一个文本字段的值发生变化?
@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号线什么都不做。事实上,当我看着文字和otherText在gdb在执行线2和3,我得到如下结果:
(gdb) p text
$1 = (NSTextField *) 0x0
(gdb) p otherText
$2 = (NSTextField *) 0x1385d1e0
这是怎么回事?我无法将输入变量传递给NSTextField的设置函数?为什么当我更改set函数的参数时,NSTextField会变为空?
这是没有问题的,但你可能不应该命名文本框之类的东西'text'。这个名字应该指向一个模式对象,就像'NSString'一样。 – 2009-12-28 22:52:54
你说得对,但我只是在测试它。 – Chetan 2009-12-28 22:57:18
此外,您的问题与NSWindowController无关。我改变了问题的标题来描述事实,而不是你的假设。 – 2009-12-29 00:33:09