Jack Humphries
Jack Humphries

Reputation: 13267

NSPopUpButtonCell indexOfSelectedItem always returns 0

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?

Upvotes: 0

Views: 246

Answers (2)

rdelmar
rdelmar

Reputation: 104082

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.

Upvotes: 3

Mundi
Mundi

Reputation: 80265

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

Upvotes: 0

Related Questions