FROM : Adam P Jenkins
DATE : Tue Feb 19 20:08:37 2008
When binding to NSPopupButtons, you can bind the "content" and
"contentValues" as separate bindings. The contentValues array
specifies the values that will be displayed in the popup menu, and
"content" is what actually gets returned as the value when an item is
selected. So you could for example bind content to an array of
NSNumber objects, and bind contentValues to an array of corresponding
descriptive strings that you want to appear in the popup menu.
Alternatively you could only bind content, and specify a value
transformer to go between the displayed representation and the numeric
representation.
See the Cocoa Bindings Reference for more info:
http://developer.apple.com/documentation/Cocoa/Reference/CocoaBindingsRef/CocoaBindingsRef.html
Specifically go to the NSPopupButton section and read the Value
Selection Bindings section. These bindings are accessible from the
bindings tab in IB's inspector for a popup.
On Feb 19, 2008, at 1:05 PM, Lukas Heiniger wrote:
> Hi All
>
> I'm having problems updating my data model when the user makes a
> selection from an NSPopupButtonCell in a NSTableView.
>
> Here's the setup: I have a NSTableView containing three columns. One
> of the columns ought to represent integer values from the model,
> i.e. it should show some descriptive title instead of the integer
> value itself. Of course this also means if the user selects a
> different title from the popup menu, the model should be updated to
> the represented value.
>
> I've tried two different approaches to achieve this but eventually
> got stuck at both of them.
>
> 1. Binding the NSPopupButtonCell to the data model
> There's a simple example described in http://developer.apple.com/documentation/Cocoa/Conceptual/CocoaBindings/Tasks/onerelation.html
> . The Problem is that they update the model with the actual item
> that is selected in the popup, whereas in my case, the title shown
> in the popup menu is only a representation of some underlying
> (integer) value which should be changed.
> What's the best way to do this? Implement a value transformer?
>
> 2. Implementing an action to manually update the model when a
> selection is made
> Here I see some strange behaviour. I'm getting the record which
> should be updated by calling [[arrayController selectedObjects]
> objectAtIndex:0]. This however seems to return the previously
> selected record. Let's say for example row 10 is selected. Now when
> I click on the PopupButtonCell in row 3 it changes the selection
> (visually) but still updates the value in row 10. It looks like the
> action is invoked before the arrayController is informed about the
> change in selection.
> What could I do about this?
>
> _______________________________________________
>
> Cocoa-dev mailing list (<email_removed>)
>
> 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:
> http://lists.apple.com/mailman/options/cocoa-dev/<email_removed>
>
> This email sent to <email_removed>
DATE : Tue Feb 19 20:08:37 2008
When binding to NSPopupButtons, you can bind the "content" and
"contentValues" as separate bindings. The contentValues array
specifies the values that will be displayed in the popup menu, and
"content" is what actually gets returned as the value when an item is
selected. So you could for example bind content to an array of
NSNumber objects, and bind contentValues to an array of corresponding
descriptive strings that you want to appear in the popup menu.
Alternatively you could only bind content, and specify a value
transformer to go between the displayed representation and the numeric
representation.
See the Cocoa Bindings Reference for more info:
http://developer.apple.com/documentation/Cocoa/Reference/CocoaBindingsRef/CocoaBindingsRef.html
Specifically go to the NSPopupButton section and read the Value
Selection Bindings section. These bindings are accessible from the
bindings tab in IB's inspector for a popup.
On Feb 19, 2008, at 1:05 PM, Lukas Heiniger wrote:
> Hi All
>
> I'm having problems updating my data model when the user makes a
> selection from an NSPopupButtonCell in a NSTableView.
>
> Here's the setup: I have a NSTableView containing three columns. One
> of the columns ought to represent integer values from the model,
> i.e. it should show some descriptive title instead of the integer
> value itself. Of course this also means if the user selects a
> different title from the popup menu, the model should be updated to
> the represented value.
>
> I've tried two different approaches to achieve this but eventually
> got stuck at both of them.
>
> 1. Binding the NSPopupButtonCell to the data model
> There's a simple example described in http://developer.apple.com/documentation/Cocoa/Conceptual/CocoaBindings/Tasks/onerelation.html
> . The Problem is that they update the model with the actual item
> that is selected in the popup, whereas in my case, the title shown
> in the popup menu is only a representation of some underlying
> (integer) value which should be changed.
> What's the best way to do this? Implement a value transformer?
>
> 2. Implementing an action to manually update the model when a
> selection is made
> Here I see some strange behaviour. I'm getting the record which
> should be updated by calling [[arrayController selectedObjects]
> objectAtIndex:0]. This however seems to return the previously
> selected record. Let's say for example row 10 is selected. Now when
> I click on the PopupButtonCell in row 3 it changes the selection
> (visually) but still updates the value in row 10. It looks like the
> action is invoked before the arrayController is informed about the
> change in selection.
> What could I do about this?
>
> _______________________________________________
>
> Cocoa-dev mailing list (<email_removed>)
>
> 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:
> http://lists.apple.com/mailman/options/cocoa-dev/<email_removed>
>
> This email sent to <email_removed>
| Related mails | Author | Date |
|---|---|---|
| Lukas Heiniger | Feb 19, 19:05 | |
| mmalc crawford | Feb 19, 19:11 | |
| Adam P Jenkins | Feb 19, 20:08 |






Cocoa mail archive

