• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: windowDidLoad Not Called
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: windowDidLoad Not Called


  • Subject: Re: windowDidLoad Not Called
  • From: "Mike Sheffield" <email@hidden>
  • Date: Mon, 12 Apr 2004 10:12:05 -0500

From: Scott Anguish <email@hidden>
To: "Mike Sheffield" <email@hidden>
CC: email@hidden
Subject: Re: windowDidLoad Not Called
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.. :-)


What would the correct design pattern be? My first impulse was to set my window controller to be File's Owner. If I do that, though, IB complains that it's not a subclass of NSApplication. If I run it anyway, I lose a bunch of standard behavior, like the ability to quit the application. If I then don't instantiate the controller subclass in my Nib file, I have to setup all my outlets and actions manually in code. This doesn't seem right either. Thus I arrived at my current solution -- leaving File's Owner as NSApplication and instantiating my window controller subclass in my Nib file.

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.


I switched to using awakeFromNib and all is well.


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.. :-)


Thanks for the help. It makes a lot more sense now.

Mike

_________________________________________________________________
Free up your inbox with MSN Hotmail Extra Storage! Multiple plans available. http://join.msn.com/?pgmarket=en-us&page=hotmail/es2&ST=1/go/onm00200362ave/direct/01/
_______________________________________________
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.


  • Follow-Ups:
    • Re: windowDidLoad Not Called
      • From: Scott Anguish <email@hidden>
  • Prev by Date: Re: NSTableView and NSImageCell
  • Next by Date: Re: Java-Cocoa drawing -- help!
  • Previous by thread: Re: windowDidLoad Not Called
  • Next by thread: Re: windowDidLoad Not Called
  • Index(es):
    • Date
    • Thread