我使用如下代码在OSX应用程序中创建了几个NSTextView对象:
NSTextView *testTextView = [[NSTextView alloc] initWithFrame:NSMakeRect(0, 700, 1200, 100)];
[testTextView setFont:[NSFont fontWithName:@"HelveticaNeue-Light" size:18]];
[testTextView setDelegate:self];
[testTextView setBackgroundColor:[NSColor lightGrayColor]];
[testTextView setString:@"Some text to populate this lovely NSTextView. I would like to be able to edit this text but I can't."];
[testTextView setEditable:TRUE];
[[self.window contentView] addSubview:testTextView];
[self.window makeFirstResponder:testTextView];NSTextView显示在屏幕上是正确的,文本是可见的,但我无法编辑文本。
有人能告诉我我做错了什么吗?
非常感谢
本
发布于 2015-01-06 10:20:10
如果您使用的是无标题窗口,则对象无法编辑,如NsTextField,NsTextView.
如果您使用的是“无标题”窗口,则该窗口必须能够成为一个关键窗口,您需要创建NSWindow的子类并覆盖-canBecomeKeyWindow,如下所示:
-(BOOL)canBecomeKeyWindow {
return YES;
}https://stackoverflow.com/questions/27796223
复制相似问题