I have a simple Cocoa app using a NSWindowController subclass. In the nib I have set:
- File Owner’s class to my NSWindowController subclass
- The ‘Window’ outlet of the File’s Owner to the main NSWindow in the nib.
The init method of my NSWindowController subclass is called (I call super), but not matter what I do windowDidLoad is never called.
I must be missing something obvious, but for the life of me I can’t figure out what it is.
You’re trying to create the instance of
NSWindowControllerby instantiating it in another nib. However, when you instantiate an object in a nib file, it is initialized by calling-initWithCoder:.-initWithCoder:is not a designated initializer ofNSWindowController, so your instance ofNSWindowControllernever actually loads its nib.Instead of instantiating your
NSWindowControllerinstance by placing it in theMainMenu.xibfile in Interface Builder, create it programmatically:In AppDelegate.h:
In AppDelegate.m:
In YourWindowController.m: