Take the 2-minute tour ×

I am creating a custom class which is inherited from NSPanel and this panel is my landing screen of the application.

I am adding a NSTextField on it, which is visible on the screen. Problem is that the textfield is not editable.

However, if i create a new cocoa project and run the same addSubview code for textfield, all is good, i am able to edit the textfield.

It seems to me like problem is with my custom panel, but i am not able to hunt it down.

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

share|improve this question

1 Answer 1

Override the method in NSPanel subclass,

- (BOOL)canBecomeKeyWindow {
    return YES;
share|improve this answer
It is correct and that simple. –  uchuugaka Apr 30 at 12:18

Your Answer


