Re: best practice for sharing NSControllers between window controllers?
Re: best practice for sharing NSControllers between window controllers?
- Subject: Re: best practice for sharing NSControllers between window controllers?
- From: email@hidden
- Date: Wed, 24 Aug 2005 13:11:39 -0500
I have an application with two windows into the document; the second
one shows
a summary of records in the first using a table view. Here's what
I've done:
I have two window controllers and two nibs. The main window
controller's nib is
actually set to have the document as file's owner.
The second window controller's nib has an array controller whose
content is linked
to the document by binding to document.records, where records is a
method on
the main document subclass that returns an array of the document's
content.
The table view is then bound to this (second) window controller's
array controller.
Shazam!
I need the second window controller's controller to allow filtering
using a search
field; otherwise it should be possible to bind the table view
directly to the document's
data directly -- but then the second window's table would be affected
by any filter
applied to the main document.
I have an app which currently has two controller classes, one for
each of two main windows (app window and a rather complex properties
window); let's call them AppController and PropertiesController.
Each of these two windows lives in its own nib file, and each nib
file of course has an instance of the relevant controller. This
being a core data + bindings application, each of these two
controllers/windows has a number of NSController instances which
manage the view contents. So far so good.
For the most part, the NSControllers are specific to the window in
which they live and don't need to be shared. The one exception is
the NSArrayController in my main window which contains my "top-level"
entities (call it Controller A). When the properties window/
controller is invoked, it needs to be able to retrieve Controller
A's current selection. This is where I can see several
possibilities, and I'm wondering if the experts can help me decide
between them:
1) PropertiesController's init function takes an instance of
AppController as an argument, and invokes an appropriate accessor to
retrieve Controller A. PropertiesController can then get the current
selection from Controller A and proceed.
2) PropertiesController's init function takes Controller A itself as
an argument, and then accesses it as above. This is more specific,
but might be less flexible if more communication is necessary between
the two controllers in the future.
3) Having two separate controllers is stupid in this case.
AppController should be set as File's Owner of PropertiesWindow as
well, and then you don't have to worry about this whole thing. (I
don't think this is right, but what do I know?)
4) You're doing something fundamentally wrong with NSControllers,
sonny, and here's what it is.
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden