Cocoa – Loading NIB file using NSWindowController doesn’t set window or top level objects

cocoainterface-builder

I have a NIB file that I load using NSWindowController initWindowNibName. The NIB file contains one NSWindow. It's File's Owner is of class NSWindowController. I've connected the window outlet from File's Owner to the Window.

When I load the NIB, [windowController window] is nil and so is the top level objects array. However, I can still call [windowController showWindow:nil] and successfully show the window.

Something just doesn't seem right here. I've confirmed the connections and the File's Owner are OK. Infact, when I look at the _owner value of the windowController instance in the debugger I see it pointing to itself as I expect.

Any suggestions on what might be going on?

Thanks!

Best Answer

When you say [windowController window] is nil, how are you determining this? The NIB isn't actually loaded until -window is called for the first time. So if you're looking in the debugger you'll see _window as nil until you call showWindow:. After that, _window should have a non-nil value.

Related Topic