Re: Window 'close' action fails
Re: Window 'close' action fails
- Subject: Re: Window 'close' action fails
- From: Erik Buck <email@hidden>
- Date: Fri, 15 Aug 2008 21:55:45 -0400
- init
{
[NSBundle loadNibNamed:@"SPlotWindow.nib" owner:self];
This step un-archives all of the objects in SPlotWindow.nib, restores
all connections within the nib including connections made to File's
Owner which you just specified, and calls -awakeFromNib for all of the
un-archived objects and Files Owner which is "self" in this case.
[super initWithWindowNibName:@"SPlotWindow.nib"];
Assuming that this -init method is in a subclass on
NSWindowController, the message to super loads all of the objects in
SPlotWindow.nib, restores all connections within the nib including
connections made to File's Owner which you just specified, and calls -
awakeFromNib for all of the un-archived objects and Files Owner which
is "self" in this case. You might think this is redundant with the
first line in the method because IT IS! The second set of connections
replace the first set of connections. The first bunch of un-archived
objects still linger in memory and are probably leaked.
[splotView initWithFrame:[splotView frame]];
I assume that splotView was set via a connection made to File's Owner
in the nib and restored (twice) when the nib was loaded. If so, it is
an error to try to re-initialze splotView. It was fully initialized
when un-archived and via -awakeFromNib. If splotView was not set in
the nib, you are trying to initialize a nil pointer which accomplishes
nothing. If splotView is nil then [splotView frame] returns an
undefined value that is probably garbage.
return self;
}
I do wonder why it is improper to:
1. load a nib, then
2. init a WindowController instance using that nib, and
thenInitializing an NSWindowController with
3. init an NSView instance defined as part of the nib using the nib
I would say, based on the code you posted, that you wonder why because
you don't understand that a nib file is an archive of objects, you
don't understand unarchiving or nib loading in general, you don't know
that Cocoa objects can't be re-initialized, and I would guess that you
have never completed even the most trivial of Cocoa tutorials or
samples that implement a designated initializer.
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden