【发布时间】:2011-10-03 21:20:28
【问题描述】:
我刚刚开始使用一个包含 NSTextField 的 NSWindow。 appdelegate.h 有这个:
NSWindow *window;
NSTextField *userIDText;
@property (nonatomic, retain) IBOutlet NSWindow *window;
@property (nonatomic, retain) IBOutlet NSButton *nextButton;
@property (nonatomic, retain) IBOutlet NSTextField *userIDText;
appdelegate 在 Interface Builder 中连接到窗口和文本字段,然后在 .m 文件中:
@synthesize userIDText;
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification {
[userIDText setStringValue:@"user"];
NSLog(@"UserIDTextString: %@", [userIDText stringValue]);
(我还尝试了除@“user”作为字符串之外的其他东西) 日志仅显示 (null),文本字段未更改。我究竟做错了什么?我现在在互联网上搜索了大约 5 小时,这显然是我想念的非常简单的事情。
【问题讨论】:
-
你的插座设置好了吗?设置断点以确保 userIDText 不是 nil
-
我之前做过这个,只是想写“当然,就像说我在 Interface Builder 中连接了它们”,但后来我检查了一下,它不是。也许我首先做错了什么,然后在尝试修复它时我再次取消了插座。谢谢你提示我正确的方向:)
标签: objective-c xcode cocoa interface-builder nstextfield