How to make NSTextField editable

I am creating a custom class that is inherited from NSPanel, and this panel is my application touch screen.

I add an NSTextField to it, which is displayed on the screen. The problem is that the text box is not editable.

However, if I create a new cocoa project and run the same addSubview code for the text field, all is well, I can edit the text field.

It seems to me that the problem is related to my custom panel, but I can not track it.

Here is my code:

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...

+4
source share
1 answer

Override the method in a subclass of NSPanel,

 - (BOOL)canBecomeKeyWindow { return YES; } 
+3
source

All Articles