Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why can't I get focus within a NSPanel when the "Title Bar" is set to not appear?

If I create a project in Xcode 4.1, and set the MainMenu.xib to have two NSPanels, and put a NSTextField in both panels, if I set one of the NSPanels to not show the "Title Bar", then the textfield within that panel can not be clicked on or given focus.

Why??

like image 651
Jeremy Smith Avatar asked Sep 11 '11 15:09

Jeremy Smith


1 Answers

A window (or a panel) without a titlebar cannot become key, so it can't get the focus. You have to subclass it and override its - (BOOL)canBecomeKey method, like this:

@interface MyPanel : NSPanel
@end

@implementation MyPanel

- (BOOL)canBecomeKeyWindow {
    return YES;
}

@end
like image 68
Nickkk Avatar answered Nov 08 '22 02:11

Nickkk