Re: NSPopupButton Bindings-Related Issue
Re: NSPopupButton Bindings-Related Issue
- Subject: Re: NSPopupButton Bindings-Related Issue
- From: Ken Thomases <email@hidden>
- Date: Sat, 28 Jun 2008 01:30:47 -0500
On Jun 27, 2008, at 11:01 PM, Keary Suska wrote:
Generally, my needs are simple. In this case, I need a sheet that
displays
an nspopupbutton populated with product names, where a user can
select an
item from the popup and a description of the item would appear in a
designated space below the control, and of course I want to retrieve
the
value after the sheet is dismissed, providing that the correct
button is
pressed. Sounds easy, right?
So, I have an NSPanel with an NSPopupButton, NSTextField, and two
buttons
("Cancel" and "Use"). The NSPopupButton "content" is bound to
"ProductController", which is a special NSArrayController subclass
whose
content is an array objects I am interested in, with key
"arrangedObjects"
no key path. "Content values" is bound to same with key path "name".
"Selected value" is bound to same but with controller key
"selection" and
key path "name". NSTextField "value" is bound to ProductController
"selection" key path "descrip".
The last two bindings are incorrect, I think. Bind the pop-up's
Selected Object to a property of your model, not the array
controller's selection. That is, when the pop-up has an item
selected, it will stuff that object (the "product") into that property
of your model.
Then, binding your text field's Value to that same model property,
except adding on ".descrip" to the key path.
This sort of arrangement is illustrated in the "Real-World Example" in
the Cocoa Bindings Programming Topics: <http://developer.apple.com/documentation/Cocoa/Conceptual/CocoaBindings/Concepts/WhatAreBindings.html#//apple_ref/doc/uid/20002372-181136
>.
In that example, the similarity to what I described above is a bit
obscured by the fact that there's a list of attackers and the pop-up
is for selecting the weapon of the selected attacker. So, the pop-
up's Selected Object binding does go through an array controller's
selection, but it's not the same array controller which provides the
content for the pop-up. Try to imagine that example if there were
only a single attacker in the model, and therefore the first array
controller were removed (or replaced by just an NSObjectController).
Okeydoke. BTW, there are some popup items that I want disabled, so I
turn
off autoenableitems in awakeFromNib and disable them before I
display the
sheet. Peachy keen cool. Popup appears as expected. However, when I
select
an item, the NSTextField doesn't update. Furthermore, all of the
disabled
items automagically enable (that's bad too). Crazy, huh?
Any ideas, anyone?
I don't know what's going on there.
_______________________________________________
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