小编And*_*eas的帖子

NSTextField不会setStringValue

我刚刚开始使用包含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小时,显然我真的很简单.

xcode cocoa objective-c interface-builder nstextfield

5
推荐指数
1
解决办法
3469
查看次数