Re: windowDidLoad not getting called
Re: windowDidLoad not getting called
- Subject: Re: windowDidLoad not getting called
- From: Bill Cheeseman <email@hidden>
- Date: Fri, 20 Mar 2015 04:54:12 -0400
> On Mar 19, 2015, at 5:29 PM, Ken Thomases <email@hidden> wrote:
>
> Marking the window Visible at Launch obviously can't trigger the loading of the NIB, since it's a setting that's stored in the NIB.
Yes, I lost my focus when I said that and incorrectly conflated the loading and the showing of the window. My original post to this thread simply stated that the nib file's Visible at Launch setting is an alternative to referencing the window property or calling -showWidow to display the window, and that's what I meant to say. I believe I am right, when the application launch sequence is set up as I set up mine.
My launch sequence goes like this: My Info.plist file designates MainMenu as the application's principal nib file. My MainMenu nib file names NSApplication as file's owner, it contains the menu bar and my archived appDelegate object, and it connects appDelegate as NSApplication's delegate. MainMenu.xib does not contain a window object, as Ken has recommended. At launch, MainMenu is loaded as the designated principal nib file, its appDelegate archive is unarchived, and NSApplication calls appDelegate's implementation of the -applicationDidFinishLaunching: delegate method. My implementation of the delgate method then explicitly creates my window controller object and initializes it using -initWithWindowNibName:"MainWindow". This is what loads my MainWindow nib file and calls its -windowDidLoad method. When the nib file loads, somebody notices that MainWindow.xib's Visible at Launch setting is set, so it immediately shows the window. My code requires no explicit reference to the window property and no call to -showWindow or -makeKeyAndOrderFront: to make the window appear. The Visible at Launch setting in the MainWindow nib file is sufficient by itself, which is the only point I was trying to make.
At least, that's how I understand it works, and I run into no difficulties when I do it this way in my applications. This has been my standard setup for single-window "shoebox" or library applications for a while now, although it is only more recently that I switched from calling -showWindow explicitly to relying on the Visible at Launch setting on the general principle that it is best to let your nib files do as much as they can unless you need greater control. I should have mentioned in my original post that the Visible at Launch setting would not be sufficient if you use the -initWithWindow: designated initializer, as the OP is doing, because, as Quincey pointed out, that initializer expects you to load the nib file or create the window yourself at some point before you create the window controller.
--
Bill Cheeseman - email@hidden
_______________________________________________
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