Re: windowDidLoad Not Called
Re: windowDidLoad Not Called
- Subject: Re: windowDidLoad Not Called
- From: Scott Anguish <email@hidden>
- Date: Mon, 12 Apr 2004 05:52:34 -0400
On Apr 11, 2004, at 2:04 AM, Mike Sheffield wrote:
Hi,
I have a trivial problem that I'm sure someone will be able to
identify quickly, but is driving me mad. I have a simple (non
document-based) Cocoa application. It has one window that is displayed
when the window starts. I have an NSWindowController subclass
instantiated in my nib file, and this class is set to be the
controller for the main window. All I want is to override
windowDidLoad to add some initialization code. I added this function
to my subclass, but it is never called, and it is not clear to me at
all why this would be the case. I believe I have all my connections
setup properly in IB.
Hrm.. that seems like an odd design pattern there, at least one I'd
never thought about.. to have an NSWindowController already
instantiated in a nib I mean... it's common for it to be the File's
Owner for a nib.. but I guess this works too.. :-)
I don't know that it'd ever need to actually load the window if it's
already loaded because it's part of the same nib that you're getting
the window controller from... so it may never need to load, and as a
result call windowDidLoad
You should get an awakeFromNib though... since that'll happen when the
nib is finished unarchiving initially.. and at that point you'll have
all the connections made, you could add your initialization code to
that method.
While trying to inspect this situation, I added this line to my
controller's init method.
if(self = [super initWithWindowNibName:@"MainMenu"]) {
array = [[NSMutableArray alloc] init];
NSLog(@"window: %@", [self window]);
}
The call to [self window] causes the windowDidLoad method to be
called. After this method exits, the controller's init method is
called again. When it once again executes the [self window] method,
windowDidLoad is called, after which init runs again. And so on. If I
comment out the NSLog line, windowDidLoad is never called.
Yes.. this is correct actually...
http://developer.apple.com/documentation/Cocoa/Reference/
ApplicationKit/ObjC_classic/Classes/NSWindowController.html#//
apple_ref/doc/uid/20000031/initWithWindowNibName_
- window
Returns the window owned by the receiver or nil if there isnt one. If
the window has not yet been loaded, it attempts to load the windows
nib file using loadWindow. Before it loads the window, it invokes
windowWillLoad in subclass implementations, and if the
NSWindowController has a document, it invokes the NSDocuments
corresponding method windowControllerWillLoadNib: (if implemented).
After loading the window, it invokes windowDidLoad and, if there is a
document, the NSDocument method windowControllerDidLoadNib: (if
implemented).
Does anyone have an explanation for what I'm observing? I have to
confess I'm completely stumped.
that's my stab at it.. :-)
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.