And*_*eas 5 xcode cocoa objective-c interface-builder nstextfield
我刚刚开始使用包含NSTextField的NSWindow,这是一个非常简单的应用程序(实际上还不是目标C).appdelegate.h有这个:
NSWindow *window;
NSTextField *userIDText;
@property (nonatomic, retain) IBOutlet NSWindow *window;
@property (nonatomic, retain) IBOutlet NSButton *nextButton;
@property (nonatomic, retain) IBOutlet NSTextField *userIDText;
Run Code Online (Sandbox Code Playgroud)
appdelegate在Interface Builder中连接到窗口和文本字段,然后在.m文件中:
@synthesize userIDText;
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification {
[userIDText setStringValue:@"user"];
NSLog(@"UserIDTextString: %@", [userIDText stringValue]);
Run Code Online (Sandbox Code Playgroud)
(我还尝试了除@"user"以外的其他东西作为字符串)日志只显示(null)并且文本字段不会更改.我究竟做错了什么?我现在搜索互联网大约5小时,显然我真的很简单.
您的applicationDidFinishLaunching方法在窗口加载之前被调用。这就是为什么NSLog(@"UserIDTextString: %@", [userIDText stringValue]);打印 null 并且您无法设置文本字段的值的原因。尝试使用awakeFromNib方法。
| 归档时间: |
|
| 查看次数: |
3469 次 |
| 最近记录: |