Skip navigation.
 
mlUpdating model: NSPopupButtonCell, NSTableView, Bindings
FROM : Lukas Heiniger
DATE : Tue Feb 19 19:05:02 2008

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?

Related mailsAuthorDate
mlUpdating model: NSPopupButtonCell, NSTableView, Bindings Lukas Heiniger Feb 19, 19:05
mlRe: Updating model: NSPopupButtonCell, NSTableView, Bindings mmalc crawford Feb 19, 19:11
mlRe: Updating model: NSPopupButtonCell, NSTableView, Bindings Adam P Jenkins Feb 19, 20:08