tags:

views:

82

answers:

2

I have an NSTable which includes a column of NSPopUpButtonCells. I would like to filter the NSPopUpButtonCell based on the contents of another column in the table. This feels like something that should have a fairly easy solution, but at the minute the solutions that I seem to be coming up with are very complicated. My biggest problem seems to be that when the application is running and I click on an NSPopUpButtonCell I can't find something that will activate before the Menu is displayed that will then initiate the filter. I have tried a feew things like tableViewSelectionIsChanging: but they all seem to activate after the list for the PopUpButton activates.

Any help is much appreciated.

A: 

In your tableView:willDisplayCell: delegate method, you can make a copy of the menu you're using for the cell, filter or populate it appropriately, then set that as the cell's menu. That should achieve the desired effect.

Peter Hosey
A: 

Turned out that there was an easy solution to this one. I was using an NSArrayController to control the rows in the table. Each row was an object of class InputCell. I added a method that returned an NSArray to the InputCell class and this method used [self valueForKey: ] to create a different array depending on the filter criteria for the cell. I could then use bindings to bind the content of the NSPopUpButtonCell to the array through the NSArrayController.

Ian Turner