简体   繁体   English

NSTextView-无法编辑文本

[英]NSTextView - Unable to edit text

I am creating a few NSTextView objects in an app for OSX using code like this: 我正在使用如下代码在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];

The NSTextView is displayed on screen correctly and the text is visible but I am unable to edit the text. NSTextView在屏幕上正确显示,并且文本可见,但是我无法编辑文本。

Can anyone point me as to what I am doing wrong. 谁能指出我做错了什么。

Thanks a lot 非常感谢

Ben

if you are using tittle-less window then objects unable to edit like NsTextField ,NsTextView....... 如果您使用的是无标题窗口,则对象将无法编辑,如NsTextField,NsTextView .......

If you are using title less window , that window must be able to become a key window,you need to create a subclass of NSWindow and override -canBecomeKeyWindow as follows: 如果使用的是无标题窗口,则该窗口必须能够成为键窗口,您需要创建NSWindow的子类并重写-canBecomeKeyWindow,如下所示:

-(BOOL)canBecomeKeyWindow {

    return YES;

}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM