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 06:53:54 -0400
> On Mar 20, 2015, at 5:21 AM, Ken Thomases <email@hidden> wrote:
>
> On Mar 20, 2015, at 3:54 AM, Bill Cheeseman <email@hidden <mailto:email@hidden>> wrote:
>
>> 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.
>
> Nope. That's not enough. A window controller does not load the NIB (nor call -windowDidLoad) just because it's been allocated and initialized with a NIB name. Something has to be requesting the window.
Yes, you're right. Re-examining my appDelegate code and looking at the backtrace from -windowDidLoad as you suggested, I see that in -applicationDidFinishLaunching:, right after I create and initialize the MainWindowController object, I set an appDelegate window outlet programmatically to mainWindowController.window, where mainWindowController is an instance variable of type MainWindowController, my NSWindowController subclass. So I do reference the MainWindowController object's window property in my code, after all.
I had completely forgotten that I did this, because I did it much earlier in the development process to replace the Xcode application template's connection of an appDelegate window object in MainMenu.xib. The template doesn't use a window controller. The window reference didn't stand out when I looked at the code again because I'm still getting used to dot notation now that I'm writing code in Swift.
When I comment out my window reference in appDelegate, the -windowDidLoad method is not called and the window does not appear at launch. When I replace the window reference with a call to -showWindow, the -windowDidLoad method is again called and the window appears at launch.
I have now unselected the Visible at Launch setting in my MainWindow nib file and gone back to my former practice of calling -showWindow. My apologies for the noise. It's been educational, though -- at least for me.
--
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