Re: Binding the enabled attribute of each NSPopUpButtonCell
Re: Binding the enabled attribute of each NSPopUpButtonCell
- Subject: Re: Binding the enabled attribute of each NSPopUpButtonCell
- From: Ken Thomases <email@hidden>
- Date: Tue, 5 May 2009 21:36:46 -0500
On May 5, 2009, at 8:46 PM, Dave Geering wrote:
I've got a problem when I try to bind the enabled attribute of an
NSPopUpButtonCell.
I have set up an NSArray of custom objects, these custom objects
provide two keys that I want to use for binding (and other keys for
other uses). The two keys are "optionTitle" and "optionAllowed". I
have an array controller in my nib that I bind to my NSArray of custom
objects.
I populate an NSPopUpButton by binding the content to the
arrangedObjects of my array controller with MKP "optionTitle" and this
works fine.
This makes sense because the content of a pop-up button is plural, in
the sense that there are multiple items in the pop-up menu.
I'm trying to bind the NSPopUpButtonCell's enabled
attribute to the arrangedObjects of my array controller with MKP
"optionAllowed" but when my view loads an exception is raised saying
that it cannot create a boolean value from an NSCFArray.
What you're asking the frameworks to do here does not make sense.
arrangedObjects, as you can see by its name, is plural. There are
potentially multiple objects. Consequently, there are potentially
multiple optionAllowed values. And yet you're attempting to bind a
single value, the enabled state of the pop-up, to multiple values.
Were you under the impression that the enabled state indicated whether
each _item_ in the menu was enabled? It does not. It controls
whether the pop-up itself is enabled.
I think you want to bind the enabled state of the menu items within
the pop-up button cell. I'm not actually sure if that works, but
conceptually that's what you seem to want to do. The problem is that
the pop-up has some stand-in menu items when it's created in IB, but
at runtime the pop-up will be creating its own items based on the
content binding. You need to be able to provide a "prototype menu
item" (the way that, for example, NSMatrix allows you to specify a
prototype cell) with bindings already configured, but I see no way to
do that.
Perhaps you can tell the NSPopUpButton not to automatically enable its
items (-setAutoenablesItems:NO) and then observe the
NSPopUpButtonWillPopUpNotification notification and enable/disable the
items in response to that.
Regards,
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