如何使NSTextField可编辑

4
我正在创建一个继承自NSPanel的自定义类,这个面板是我的应用程序的着陆屏幕。
我在上面添加了一个NSTextField,它在屏幕上可见。问题是这个文本框是不可编辑的。
然而,如果我创建一个新的Cocoa项目并运行相同的addSubview代码来添加文本框,一切都很好,我可以编辑文本框。
对我来说似乎问题出在我的自定义面板上,但我无法找到它。
以下是我的代码:
NSTextField *infoTextField = [[NSTextField alloc] initWithFrame:rect];
[[window contentView] addSubview:infoTextField];
[infoTextField setDelegate:self];
[[infoTextField window] becomeFirstResponder];
[infoTextField setTextColor:[NSColor blackColor]];
[infoTextField setDrawsBackground:YES];
[infoTextField setBordered:YES];
[infoTextField setSelectable:YES];
[infoTextField setEditable:YES];
[infoTextField setEnabled:YES];
[infoTextField setAlignment:NSLeftTextAlignment];
[infoTextField setStringValue:@"What are you doing?"];
[infoTextField release];

I need your help...

1个回答

3

在NSPanel子类中重写该方法:

- (BOOL)canBecomeKeyWindow {
    return YES;
}

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接