Re: NSPopUPButton and selectedTag binding seems to give me index instead
Re: NSPopUPButton and selectedTag binding seems to give me index instead
- Subject: Re: NSPopUPButton and selectedTag binding seems to give me index instead
- From: Ken Thomases <email@hidden>
- Date: Thu, 5 Mar 2009 16:09:48 -0600
On Mar 5, 2009, at 3:35 PM, Stuart Malin wrote:
First, what works: I drive the content and contentValues from an
object that I construct which is an indexed accessor KVC (read-only)
compliant with a backing store array of NSMenuItem items.
I'm pretty sure that doesn't work like you expect it to.
The content bindings of an NSPopUpButton don't expect the bound-to
objects to be NSMenuItems, and they don't take special advantage of it
if they are. They're just generic objects as far as NSPopUpButton is
concerned. If the contentValues is bound, then the titles of the
menus in the pop-up are take from that key path. Otherwise, the
titles are obtained by applying -description to each object in the
content binding. If contentObjects is bound, then the represented
object for each item in the menu is the corresponding object in the
binding. Otherwise, it's just the corresponding object in the content
binding. The represented object is really just used when the
selectedObject of the pop-up is bound. Selecting a new item in the
pop-up sets the bound value to be the represented object for the item;
when the bound value is set in a KVO-compliant way, the pop-up changes
to show the corresponding item selected.
I suspect that NSPopUpButton is just synthesizing tags for its menu
items in this case. I see no way to specify the tags of the items
when the content is specified via bindings.
If you have a set of NSMenuItems that you want the NSPopUpButton to
use, then don't use bindings to set the content of the pop-up. Just
set the menu directly. In that case, I assume the tags are kept as
they are, and the selectedTag binding will operate as you expect.
Alternatively, you can specify the key path to the tag value as the
contentObjects binding. Then, bind selectedObject to
twitterAccountsArrayController.selection.frequency. That should have
the effect you're looking for, too.
Cheers,
Ken
_______________________________________________
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