views:

437

answers:

2

I'm trying to display an array of NSManagedObjects in a NSTableView using a custom NSCell that is able to draw the managed object properly.

For that matter, the single column of my NSTableView is binded to the arrangedObjects of a NSArrayController. I'm not using any key paths on the object.

I was under the impression that my NSCell subclass would receive a setObjectValue: message when the table view wants to draw a particular item, but this isn't happening. But that wouldn't even work since the NSManagedObjects aren't conforming to the Copying protocol.

I suspect this is a common task and that there must be some simple way to do this, but I really don't see it right now.

Any insight would be appreciated.

A: 

I managed to make it work by binding the table column with the objectID keypath of the managed object model (which is NSCopying conforming). The cell then retrieve the actual NSManagedObject using the ID. It works like a charm!

Martin Cote
+2  A: 

You need to bind to a specific property of the bound objects. If you really need one cell to draw the entire value, then you should bind to the objectID, as Martin suggests, but instead of re-fetching in the cell’s drawing code you can use the -tableView:willDisplayCell:forTableColumn:row: delegate method to set the object as a value for a custom property of the cell from the array controller, avoiding both copying and fetching.

Ben Stiglitz