views:

253

answers:

1

I'm trying to create a view that's similar to Motion's properties views (screenshot). Each of my property objects contains a definition of the kind of cell it wants to display as. But at the same time, I'd like to use bindings so that values are automatically updated as they can be changed elsewhere.

I've tried a few different approaches to the problem.

  • Multiple cells and dataCellForTableColumn: while this allows rendering to happen properly for all cell types, I lose bindings.

  • NSProxy: I've also tried using a proxy object that I thought would forward all methods to the selected cell type behind it, but again, bindings don't seem to work here.

Has anybody had any experience with this kind of problem before? Or is this one of the cases where bindings isn't going to cut it, and I'll need to do the heavy lifting myself?

Cheers!

A: 

I haven't actually tested it, but you shouldn't be losing bindings when you use dataCellForTableColumn:row: ? Can you describe in a bit more detail what you've tried with respect to bindings?

You should be able to set the column's value binding to the "value" property of your object. Then if you return the correct type of cell in dataCellForTableColumn:row: it should display correctly.

Edit: --- deleted gratuitous incorrect advice about cells vs views :)

Ira Cooke
It's largely as you've said -- I have bound an NSArrayController to the table column, and the values appear correctly if I use a NSTextFieldCell. They are also edited correctly when I change them (it calls the appropriate setObjectValue: on my Property object). But when I return a NSSliderCell, it sets the value correctly, but when I drag the slider, it doesn't set the value accordingly.
Simon Wilson
I just tried a test example, and you're right it fails in just the way you've described. I'm not sure what I'm not setting up properly (in terms of bindings? represented object etc?) on the cell before returning it. Hopefully someone more knowledgable will weigh in here.
Ira Cooke
I'm not sure if this is the "correct" way yet, but if I set the table view's data source as well, and implement only tableView:setObjectValue:forTableColumn:row:, which in turn simply calls setObjectValue: on my Property class, everything appears to work. I'm keen to hear if there's an alternative way, but for now, this works for me.
Simon Wilson
Glad you got it to work. I'm quite curious about the details of how this works. If you figure out the full story let me know.
Ira Cooke