I have an NSWindowController subclass called _PreferencesWindowController with the following implementation –
@synthesize window;
- (id)init {
self = [super initWithWindowNibName:@"PreferencesWindow"];
if (!self) return nil;
return self;
}
And I tried to show the window in _PreferencesWindowController by using the following code –
_preferencesWindowController = [[_PreferencesWindowController alloc] init];
[_preferencesWindowController showWindow:nil];
It does nothing, and I checked _preferencesWindowController.window is nil from the debugger.
However if I call loadView on _preferencesWindowController the window can be loaded and is visible; _preferencesWindowController.window is no longer nil-valued –
[_preferencesWindowController loadWindow];
I looked at Apple’s documentation on NSWindowController it specifically says “you should never directly invoke loadWindow“, instead showWindow: should be used. I’m wondering what I might have missed that resulted in the above-mentioned behaviour I have been seeing.
OK I solved this by looking at the
NSWindowControllerheader file.The problem is in my header file for _PreferencesWindowController –
By removing the @property declaration and changing
NSWindow *windowivar toIBOutlet NSWindow *window,showWindow:method now works without a glitch.The property declaration must have resulted in an undefined behaviour in
showWindow:method inNSWindowController‘s implementation.