Re: Passing References During Initialization / Nib Loading
Re: Passing References During Initialization / Nib Loading
- Subject: Re: Passing References During Initialization / Nib Loading
- From: Quincey Morris <email@hidden>
- Date: Thu, 11 Jun 2009 13:59:54 -0700
On Jun 11, 2009, at 11:52, Brad Gibbs wrote:
In short, I need a more reliable way to pass references to my
MainWindowController into objects that are awaking from nib files.
Trying to set the mMainWindowController variable to
self.view.window.windowController in the awakeFromNib method seems
to be happening before the MainWindowController is instantiated, so,
it sets the variable to NULL.
I need to call a method in the MainWindowController to switch
views / viewControllers, passing in the new viewController as an
argument. I can set the mainWindowController variable in the method
that actually invokes the view switch, but that seems clunky. It
seems like there should be a method I can call to set the variable
once the view controller has awoken and the app has fully loaded.
initWithCoder and awakeFromNib happen too soon and
applicationDidFinishLaunching only gets sent to the app delegate.
You haven't really described how things are arranged, in a way that we
can understand. You have a window controller, plus a view controller
for each set of controls/objects in its own nib file? How do the view
controllers get created?
As Kyle said, to avoid having to "manually" resolve the timing of when
instance variable can be set in objects loaded from nib files, you
should use outlets instead of instance variable in objects coming from
nib files. I think your mistake is trying to connect directly to the
window controller across multiple nibs. Probably the correct solution
involves putting a 'main window controller' property in each view
controller, and putting a mViewController reference in the nib
objects. Then you'd refer to the main window controller as
mViewController.mainWindowController (or whatever).
If your view controllers are being created programmatically, you'd
pass the window controller as a parameter when creating them. If, for
some reason, you have the view controllers in your main window nib
file, then you'd use outlets to connect them to the main window
controller.
But that's all guesswork, without further information.
_______________________________________________
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