When you create a window controller with an associated nib file the window controller assumes responsibility for all aspects of managing that nib file. This includes:
Loading the nib file
When the window controller is asked to do something, it first loads its window by loading the window controller’s nib file. When it loads the nib file, the window controller sets itself as the nib file’s owner.
Freeing top-level objects when the window controller is deallocated
As the nib file’s owner, the window controller is responsible for freeing any top-level objects instantiated in the nib file. This includes the window itself and any additional objects you might have added to the nib file. The window controller automatically keeps track of these objects when it loads the nib file, and then releases them when the window controller is deallocated.
For a window controller to be able to load and use its window from a nib file, the nib file needs to have certain objects configured properly, with their outlets connected to the appropriate objects.
When a window controller loads a nib file, it sets itself as the owner of that nib file. To enable connections from the window controller to other objects in the nib file, you need to set the file’s owner of the nib file that will be managed by a custom window controller to the class of that custom window controller.
Window controllers keep track of their window using their window
outlet. The window
outlet of your window controller (set as the file’s owner in your nib file) should be connected to the window your window controller is responsible for.
While not required, it’s often convenient to set up your window controller as the delegate of the window it manages. In your nib file, connect the delegate
outlet of the window your window controller is managing to the object that represents your window controller—specifically, the file’s owner object.
Note: NSWindowController
does not depend on being the controlled window's delegate to do its job, and it doesn't implement any NSWindow
delegate methods. A subclass of NSWindowController
, however, is a fine place to put implementations of NSWindow
delegate methods, and if you do so you'll probably need to connect the delegate outlet of the window to the nib file's owner as described, but you do not have to do so for NSWindowController
itself to work properly.
For more information, see “How can I make an NSWindowController subclass that automatically uses a particular nib file?.”
© 2001, 2009 Apple Inc. All Rights Reserved. (Last updated: 2009-01-12)