문제

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?

도움이 되었습니까?

해결책

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.

다른 팁

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

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top