Re: Passing References During Initialization / Nib Loading
Re: Passing References During Initialization / Nib Loading
- Subject: Re: Passing References During Initialization / Nib Loading
- From: Brad Gibbs <email@hidden>
- Date: Thu, 11 Jun 2009 15:53:08 -0700
Hi,
Thanks for the response. I was trying to make the post short, hoping
to up my chances of getting someone to read through the entire thing
and take the time to respond. I guess I just made it confusing.
So, now for the long(er) version.
I have a single window application. It's a Core Data, non-document-
based app. At launch, the appDelegate loads the mainWindowController,
which controls the app's only window. In the main window, there are
three views -- a status bar across the top, a menu view down the left
side (Jonathan Dann's Animating Outline View embedded in a view,
rather than a window) and a content view, which takes up the rest of
the main window. The mainWindowController loads initial views for
these containers.
In each section of the menu (the outline view) is a table view with a
single column, which lists the titles for the view controllers. For
the most part, a single view controller controls a single view, which
is displayed in the content view portion of the main window. These
view controllers are subclasses of a custom subclass of
NSViewController with variables for the main managedObjectContext and
the mainWindowController.
The method call to remove the view currently in the content view
portion of the main window and replace it with the new view
controller's view is in the main window controller.
I had been manually instantiating the view controllers and passing
references to the main window controller and the main managed object
context with a custom init method ( initWithMoc: andWindowController:)
and using these arguments to set variables in the view controllers.
Today, I decided to try to refactor and clean up some code by
instantiating the view controllers in nibs, but I ran into the problem
I'm trying to describe.
Yes, I'm using 10.6, but I think the problem can be abstracted enough
to be discussed without breaking the NDA.
On Jun 11, 2009, at 1:59 PM, Quincey Morris wrote:
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
_______________________________________________
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