NSPanel with "header" not checked in Interface Builder is not displayed

So, I thought I covered my bases, but apparently I skipped one or two steps.

I have an NSPanel that displays ( makeKeyAndOrderFront: when NSStatusItem is clicked. Everything works fine, but since NSPanel displays the title bar, the panel is also draggable. (This is undesirable.)

The first screenshot shows a panel with a title bar included in Interface Builder in the Appearance category. (Sorry for the blur, still under lock and key.)

First screenshot

Changes made only in Interface Builder uncheck the "Title Bar" box. Then I save and re-run, and this is what you see in the second screenshot. While a small shadow appears, the panel does not work.

enter image description here

What I tried:

  • I subclassed NSPanel and returned YES for canBecomeKeyWindow and canBecomeMainWindow after several studies, but (before the subclass) these methods returned NO regardless of whether I used the title bar or not. Therefore, I do not think this is a problem.

  • I am sure that the frame for NSPanel is installed correctly. It has a good height, and the source is also set correctly.

Edit: Forgot to mention:

An application is a menu-only application. In the screenshot below, note that an additional entry has been added to Info.plist .

Info plist

+7
source share
2 answers

I had problems with this in the past. I was able to resolve this by first โ€œignoringโ€ other applications, and then making it a key window. Take a picture and see if it works for you.

 [NSApp activateIgnoringOtherApps:YES]; [[self window]makeKeyAndOrderFront:self]; 

Also try setting the window level of NSPopUpMenuWindowLevel during initialization.

 [[self window]setLevel:NSPopUpMenuWindowLevel]; 

I also had problems loading nib files on Mac OS X. They load "lazily", which means that they will not be initialized until they are needed. This causes a problem when you want to set specifics in a window, but you cannot, because awakeFromNib does not seem to be called due to lazy loading of nib. To fix this, here is what I have done in the past. In your deletet (or wherever you initialize your window), start the window in action by accessing the window property in the initialized class:

 wc = [[blah alloc]initWithWindowNibName:NSStringFromClass([blah class])]; (void)[wc window]; //just kicks the lazy nib loading into gear 

This way you force the nib to be initialized. Thus, when the user clicks the menu icon, the thread is already initialized, and awakeFromNib already called.

+4
source

While a small shadow appears, the panel does not work.

You say makeKeyAndOrderFront: on this NSPanel object does not display it when the application starts? I just created a sample project, NSButton runs the same type of NSPanel for display, and it works great. TitleBar enabled or not.

http://cl.ly/3d0U3C0P3u2D0m3T1w1N

+1
source

All Articles