Re: awakeFromNib and windowWillLoad : basic question
Re: awakeFromNib and windowWillLoad : basic question
- Subject: Re: awakeFromNib and windowWillLoad : basic question
- From: jean Bousquet <email@hidden>
- Date: Wed, 09 Jul 2003 11:38:30 +0200
Hello Chris,
Thanks for explanations.
But some thing doesn't work as we stated (see in the text below).
Jean
>
>
From: Chris Hanson <email@hidden>
>
On Tuesday, July 8, 2003, at 09:35 AM, jean Bousquet wrote:
>
> Here are some practical rules I observed running simple tests :
>
>
Please don't just try to derive rules of thumb about how Cocoa behaves
>
from observation. Read the documentation, it's all described in there.
>
>
> 1) The windowControllers of the windows both defined in the
>
> MainMenu.nib
>
> file (no matter if the window is or not visible at launch time) never
>
> are
>
> sent windowDidLoad (nor windowWillLoad).
>
>
Here's what should be going on:
>
>
(1) You have a subclass of NSWindowController that is instantiated in
>
your MainMenu.nib file. Let's call this instance "MyWindowController".
>
>
(2) MyWindowController has its window outlet connected to an NSWindow
>
that is also instantiated in your MainMenu.nib file. Let's call this
>
window "MyWindow". MyWindow is *not* set to be initially visible.
>
>
(3) When your application is launched, MainMenu.nib is loaded and
>
MyWindowController is sent -awakeFromNib.
Right
>
>
(4) At some point, you send MyWindowController the -showWindow: action
>
message. This should display MyWindow automatically, and
>
MyWindowController should receive both -windowWillLoad and
>
-windowDidLoad as part of that display process.
>
No, it doesn't.
I thought also MyWindowController should receive both -windowWillLoad and
-windowDidLoad when -showWindow: is invoked but it doesn't. (This surprised
me and was the origin of the history).
I created a very simple straightforward TestWindow project to be sure.
Here is the complete class used to test :
#import "MyWindowController.h"
@implementation MyWindowController
-(void)windowDidLoad
{
NSLog(@"windowDidLoad");
}
-(void)windowWillLoad
{
NSLog(@"windowWillLoad");
}
@end
In my test, the window (defined in the MainMenu.nib) is displayed by action
on the New command in the File menu (the New command is directly connected
to the action -showWindow of theMyWindowController). The window is displayed
but neither -windowWillLoad nor -windowDidLoad are invoked.
Either I did some thing wrong or what we think about windowController is
wrong or ?
>
MyWindowController will *not* be sent -windowWillLoad and
>
-windowDidLoad just because it was instantiated. It actually needs to
>
be sent -showWindow: *and* have its window outlet connected to
>
MyWindow. Furthermore, MyWindowController won't be sent -awakeFromNib
>
again as it shows the window because it has already been instantiated
>
and configured.
>
>
> 2) The windowControllers of the windows defined in another nib file
>
> (different from the MainMenu.nib file), are sent a windowWillLoad, a
>
> awakeFromNib, a windowDidLoad (in that order) each time there are
>
> instantiated.
>
>
Probably because you're actually sending these window controllers
>
-showWindow:.
Yes, in this case the WindowController subclass acts as we think it should.
Just to compare with the above which acts differently.
>
>
-- Chris
>
>
--
>
Chris Hanson, bDistributed.com, Inc. | Email: email@hidden
>
Custom Application Development | Phone: +1-847-372-3955
>
http://bdistributed.com/ | Fax: +1-847-589-3738
>
http://bdistributed.com/Articles/ | Personal Email: email@hidden
_______________________________________________
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.