• 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: James Spencer <email@hidden>
  • Date: Sun, 11 Apr 2004 09:57:05 -0500

On Apr 11, 2004, at 1: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.

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.


As both your window and your window controller are being loaded from the nib, you need to do your additional initialization in awakeFromNib if you need the nib to be loaded by the time you do the code. At the time your init method is called above, the application is in the middle of loading the nib and then you are telling it to load it again with initWithWindowNibName which of course calls init again. The call to [self window] loads the window if it isn't already loaded and i would appear that by interfering with the loading, you are making the window controller think it isn't loaded yet.

Spence

James P. Spencer
Rochester, MN

email@hidden

"Badges?? We don't need no stinkin badges!"
_______________________________________________
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.


References: 
 >windowDidLoad Not Called (From: "Mike Sheffield" <email@hidden>)

  • Prev by Date: Sorting a NSOutlineView
  • Next by Date: Re: Passing C Style Function Callbacks in Cocoa
  • Previous by thread: windowDidLoad Not Called
  • Next by thread: Re: windowDidLoad Not Called
  • Index(es):
    • Date
    • Thread