Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: -windowDidLoad not getting called



On Apr 21, 2008, at 5:34 PM, Rick Mann wrote:

That's all a rather unfortunate inconsistency (and part of why I sit here learning Cocoa and thinking, "I thought Cocoa was supposed to be this great thing").

I basically want my controller to go do some stuff after it and the window are loaded. -setWindow seems like an ugly place to do this, and -init is probably too early. Is there a better place?

It's not so inconsistent, really. A window controller is intended to be File's Owner for the nib containing a window, not be a separate top- level object in some other nib. If you do that, then the window controller will load the nib itself, and thus load the window within it too and send itself -windowDidLoad at the end. Since your window controller isn't what loaded the nib containing the window, its - windowDidLoad won't be invoked.


You could refactor your nib so that your window and its owning window controller are in their own nib, with the window controller as File's Owner; check out "Decompose Interface" in Interface Builder 3 for an easy tool that will get you partway there. (You'll have to switch from using a separate object to using File's Owner as an instance of your NSWindowController subclass yourself.)

NSWindowController isn't the only class in Cocoa that works this way; NSViewController also does, for similar reasons. It's a great substrate on which to build reusable "component" views.

  -- Chris

_______________________________________________

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:
http://lists.apple.com/mailman/options/cocoa-dev/email@hidden

This email sent to email@hidden
References: 
 >-windowDidLoad not getting called (From: Rick Mann <email@hidden>)
 >Re: -windowDidLoad not getting called (From: Ken Thomases <email@hidden>)
 >Re: -windowDidLoad not getting called (From: Rick Mann <email@hidden>)



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.