Re: [Newbie]:Bindings and pulldown menus
Re: [Newbie]:Bindings and pulldown menus
- Subject: Re: [Newbie]:Bindings and pulldown menus
- From: Frederick Cheung <email@hidden>
- Date: Wed, 15 Sep 2004 02:55:54 +0200
On 15 Sep 2004, at 02:46, J Tichenor wrote:
I'm trying to bind the value of an NSArray to a pulldown menu. I have
a value called projectTitles, which is a pointer to an NSArray of
project titles, obviously, distilled out of the children of a
masterProjectObject.
I am sure I am using proper KVC -- projectTitles exists both as a
IBOutlet NSArray variable (don't think the IBOutlet matters for
bindings?) and as a method which returns a pointer to the array.
In IB, I have created an NSArrayController object, added a
projectTitles key, and then set the Object Class Name to my main data
controller object, where the value of the projectTitles array is set
and passed.
I have then bound the pulldown menu to the NSArrayController, in
contentValues under bindings. I have set the controller key to be
arrangedObjects and set Model Key Path to be projectTitles. I've
fiddled around, trying different bindings, and am just not getting
anywhere. I suspect it might have something to do with when my data
model is loaded -- I have it in awakeFromNib -- but I assume that
anytime that projectTitles value changes, the binding informs the
pulldown menu to reload it's item list?
Anyway, I hope I've described this well enough. I know this is
Bindings 101 but I've gone through both the Apple docs and mmalc's
great but pretty advanced reference, so I'm at a bit of a loss.
Suspect once I understand how this is done everything else should
(hopefully) fall more smoothly into place? :-)
You've gotten things a little wrong. You need to bind the contentArray
of the NSArrayController to your main data controller, with the model
key path projectTitles, no controller key (assuming that this main data
controller is the file's owner). You set the Object Class Name to the
class of the elements of the NSArray, so if you have an array of
instances of Foo, you would set it to foo.
You then bind the content values to the nsarraycontroller. The model
key path depends on what you want the popup to display. If your array
objects have some KVC compliant variable blah that you wanted the popup
to show, you'd set the model key path to blah.
This is easier to work out if you have a working example you can fiddle
with, IIRC the Todos example on mmalc's page demonstrates this.
Fred
_______________________________________________
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