views:

1329

answers:

2

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!

+1  A: 

Have you subclassed NSWindowController?

When I do this, I use an NSWindowController called MyWindowController and call initWithWindowNibName: in the subclass's init

And then , set File's Owner to point to the MyWindowController class.

Abizern
You don't need to subclass NSWindowController. It's allowed, but not required, and shouldn't solve psychotik's problem.
Peter Hosey
+2  A: 

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.

Rob Napier
Yep, you're right. I was asserting that window wasn't null before i called [controller window]. I'm still not used to a lot of the 'magic' that Cocoa does for you under the covers... it's smarter than I am, or makes me look dumber than I think I am.
psychotik
The longer I develop in Cocoa, the more I learn how little magic it really is (except for KVO; method swizzling is magic even when you understand it). The trick is not to rely on any internal implementation details. Don't assume you know what _window means. It has an underscore; it's not your business. The public interfaces are extremely consistent in their behaviors. Don't try to sneak around them. Good luck!
Rob Napier