Question

I have a NSTableView with each cell containing a NSPopUpButtonCell. I have set the NSPopUpButtonCell 's action to a method that simply checks for the selected index (so that this can be saved and the table reloaded).

thePopUpButtonCell.action = @selector(popUpChangedValue);

-(void)popUpChangedValue {

    NSLog(@"%ld", [thePopUpButtonCell indexOfSelectedItem]);

}

No matter what I select, it says that the selected index is 0, even though it is not. Do you know what is causing this?

Was it helpful?

Solution

The way I do this is with bindings. You would need a field in your array (a key value pair in an NSDictionary) to hold the value of the popup's selection. In IB you would have an array controller whose content array was bound to your array (that includes the dictionary I mentioned above). The column with the popup would have its Selected Value bound to the array controller's arrangedObjects with a model key path of the key name in your dictionary. When you change the selection in the popup, the array's value will be updated through the magic of bindings.

OTHER TIPS

Looks like your thePopUpButtonCell is perhaps also nil? Some problem with retaining etc. perhaps.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top