NSTableView has multiples
NSCells (indirectly via
NSTableColumn). NSCell follows the Flyweight design pattern; they're cookie-cutters. There's one cell per column and it's asked to draw itself for each row. "Here's a value, draw it on the first row; here's the value for the second row, etc." This is in contrast to view-based tableviews which have a view instance per cell.
I've subclassed NSPopUpButtonCell and for each
setXxxValue: method, I call
NSLog(); and forward the message to the super class. The only method which gets called (say, when adding new rows, or otherwise refreshing the table) is
setObjectValue:. This is expected from the documentation... but
null is the only thing passed to it!! It should be passed an NSNumber with the selected item index.
My table draws fine. I'm just trying to understand this because I want to extend/change the behaviour of the cell (obviously as I would'nt have needed a subclass otherwise).
<strong>Question:</strong> How is this possible? How is the NSPopUpButtonCell being set to a value in order to draw the right value for each row. Even considering bindings, it's NSTableColumn doing the heavy lifting, no? What am I missing?
"Every row in a table shares the same popup menu" – that doesn't need to be the case.
In addition to setting the table column's value binding, set the cell's content binding to an array property of your model object, via your array controller.
You can keep the code which determines the options in the model (just create an array of strings). That way you won't need a custom subclass.