2

我正在尝试使用能够正确绘制托管对象的自定义来显示NSManagedObjects一个数组。NSTableViewNSCell

就此而言, my 的单列NSTableView绑定到arrangedObjectsa 的NSArrayController。我没有在对象上使用任何关键路径。

我的印象是,当表格视图想要绘制特定项目时,我的NSCell子类会收到一条setObjectValue:消息,但这并没有发生。但这甚至行不通,因为NSManagedObjects不符合Copying协议。

我怀疑这是一项常见的任务,并且必须有一些简单的方法来做到这一点,但我现在真的看不到它。

任何见解将不胜感激。

4

2 回答 2

3

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.

于 2009-10-27T17:46:00.450 回答
0

objectID我设法通过将表列与托管对象模型(NSCopying符合)的键路径绑定来使其工作。然后单元格NSManagedObject使用 ID 检索实际值。它就像一个魅力!

于 2009-10-25T03:11:45.803 回答