Re: programmatically instantiating bound view/controller
Re: programmatically instantiating bound view/controller
- Subject: Re: programmatically instantiating bound view/controller
- From: "Kyle Sluder" <email@hidden>
- Date: Sat, 2 Feb 2008 15:25:47 -0500
On Feb 2, 2008 2:25 PM, Diez B. Roggisch <email@hidden> wrote:
> If using the NIB-approach, if there are ways to get the view (I never
> did load a NIB myself so far, excuse my ignorance) shouldn't I be able
> to get a reference to my NSObjectController as well? Then I'd set the
> content on that.
Nib loading is done using the NSBundle AppKit additions; documentation
is at http://developer.apple.com/documentation/Cocoa/Reference/ApplicationKit/Classes/NSBundle_AppKitAdditions/Reference/Reference.html
. Every nib has three proxy objects available: the file's owner, the
application, and the first responder. The file's owner is nothing
more than the object passed as the second argument to +[NSBundle
loadNibNamed:owner:]. In a document-based application, this is your
NSDocument subclass (or your NSWindowController subclass if you choose
to use a custom window controller).
Just like any other kind of object, the object represented by the
file's owner proxy can have IB outlets. In your case, whatever object
is the file's owner of the view is going to need to have an outlet for
the view that is wired from the File's Owner proxy to the NSView in
the nib (this is precisely how NSViewController works on Leopard).
Once the nib has been loaded, the outlet will point to the view living
in the nib. Please note that this means creating one object per nib
loaded, because each file's owner needs to be distinct! If you're
targeting only Leopard, then you don't need to create your own class
for this; just use NSViewController. It implements the exact pattern
I'm describing.
As for getting to your NSObjectController, the File's Owner is a valid
object for bindings. If you're using NSViewController,
representedObject is the key path you want to use; in the same code
that creates the NSViewController, set its represented object to be
the NSObjectController, and then you can bind all the interface items
in your loadable view to File's Owner with a keypath like
"representedObject.arrangedObjects". If you're not using
NSViewController, the class you created above is going to need some
functionality similar to this.
Good luck!
--Kyle Sluder
_______________________________________________
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