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 i开发者_开发问答s 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...
Override the method in NSPanel subclass,
- (BOOL)canBecomeKeyWindow {
return YES;
}
精彩评论