I want to use an NSComboBoxCell on some rows (not all) of some columns in an NSOutlineView. How I decide is based on the data. Imagine you have machines that you can configure. Some machines have a toggle state for which “yes” and “no” are good values, but maybe some other values make sense. In the “Toggle State” column, for the machines where it makes sense to have a ComboBox, I want the user to get an Combo Box when they try and edit the state. When they are not editing, they should just see the state, not the combo box arrows.
I sub-class NSTableColumn and my sub-class looks like this:
@interface tableColumnComboBoxCell : NSTableColumn { NSComboBoxCell *comboBoxCell ; int editRow ; }
What I am really interested in, is providing my own cell when it comes to editing that row. That’s why I provide my own dataCellForRow which simply looks like this:
I create the “Toggle State” column in the OutlineView programatically and it is created as a tableColumnComboBoxCell.
In the delegate method
This works! The reload is needed to force a refresh so my ComboBoxCell can become the cell. Otherwise you need to click one more time to start editing.
I have several problems with this solution.
*1) The NSComboBoxCell is of the kind you would get stand-alone, not in a table row. By this I mean it has the blue tag on the side, not the small little up and down arrows that you get if you dropped the NSComboBoxCell on a Table/Outline view. *2) Where I set the editRow, I am asking what’s the selectedRow. This isn’t always correct. If I tab out of one row, into a comb-box row, the selectedRow (at this stage) is still the row I am tabbing from. My CombBox now appears on the wrong row! Using editedRow doesn’t help either (and may not even work at all?). *3) I can’t quite figure out how to know when editing has finished. I set the target & action method and I just terminate editing in there. That means that if the user selects a value, they are done editing, whether they like it or not! Works, but isn’t ideal. Also, the user can get out of the edit without me knowing, leaving the NSComboBoxCell hanging there. Not at all what I want.
Change the line in ShouldEditTableColumn to the below (just ask the table what row the item is on (obviously) helps! ;)