Re: Instantiating window from nib
Re: Instantiating window from nib
- Subject: Re: Instantiating window from nib
- From: James DiPalma <email@hidden>
- Date: Tue, 23 Oct 2001 12:37:19 -0400
On Monday, October 15, 2001, at 10:51 AM, James DiPalma wrote:
Are there advantages to using NSWindowController? Its design seems to
provide many of its features for NSDocument (or any document) window:
all of the relevant features in the doc can easily be done in IB for a
non-document window. Using an NSWindowController simply to load a nib
file seems like an unnecessary introduction of a somewhat confusing
class.
Well, as the person who asked the original question, I'm certainly no
expert here, but NSWindowController does seem to provide some
additional functionality that is useful, although not particularly hard
to implement yourself. For one thing, it automatically cascades new
windows, and stores window size and location information in the user
defaults, restoring them the next time. These are obviously things
primarily intended for the document based application, but they can be
useful in other situations.
The documentation for NSWindowController lists 5 features:
1. Loading and displaying the window
2. Closing the window when appropriate
3. Customizing the window's title
4. Storing the window's frame (size and location) in the defaults
database
5. Cascading the window in relation to other document windows of
the application
You mentioned loading the nib multiple times, so cascading is a useful
feature for your original post-ed question. For a non-document (NS or
otherwise), my recommendation comes from the following observations:
1. [NSBundle loadNibNamed:@"foo" owner:self] is easier than
[[[NSWindowController alloc] initWithNibNamed:@"foo" owner:self]
loadWindow] and the corresponding release of the window controller
instance
2. The close button and the close menu item both close the window
and setting releaseWhenClosed in IB will release the window
3. non-document windows don't have titles based on a filename, so
set the title in IB
4. setting the window's autosaveName can be done in IB's window
inspector
5. non-document window nibs only get loaded once, so they don't cascade
-jim