• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: [Newbie]:Bindings and pulldown menus
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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


  • Follow-Ups:
    • Re: [Newbie]:Bindings and pulldown menus
      • From: J Tichenor <email@hidden>
  • Prev by Date: Re: controlTextDidChange, backspace possible?
  • Next by Date: Re: controlTextDidChange, backspace possible?
  • Previous by thread: [Newbie]:Bindings and pulldown menus
  • Next by thread: Re: [Newbie]:Bindings and pulldown menus
  • Index(es):
    • Date
    • Thread