我使用基于视图的 NSOutlineView 来显示和选择科学应用程序的分层结构项目。
大纲列中的每一行代表一个项目,由项目特定的图标表示(在图片)、显示是否选择该项目的复选框以及该项目的名称。我需要图标、复选框和名称出现在同一单元格中,因此我使用基于视图的 NSOutlineView。
我已经实现了 NSOutlineViewDataSource 协议来向大纲视图提供数据。
方法 outlineView:objectValueForTableColumn:byItem:
提供一个自定义对象,该对象具有属性 BOOL selected
和 NSString *name
。
我在 IB 中的自定义表格单元格视图的组成如下:
我将复选框值绑定到 < code>objectValue.selected 并将标签值设置为 objectValue.name
。
正如我所希望的,大纲视图很好地显示了 objectValue 提供的名称和选择状态。
但是,如果我更改复选框的状态,则在我的数据源中不会触发 NSOutlineViewDataSource 协议中定义的方法 outlineView:setObjectValue:forTableColumn:byItem:
来提供新更改的对象值。请注意,如果我不使用单元格的自定义视图,则此操作有效。
我通过将 NSLog 语句插入到作为 setSelected
方法中,检查了单击复选框时表格单元格视图的 objectValue.selected
是否实际发生更改>对象值。 selected
成员正确更改状态。
如何将 objectValue
的更改传播回我的数据源模型?我已经检查了 NSOutlineView 的委托方法,但找不到一种方法来表明单元格视图的 objectValue 已被我的复选框更改(即单元格视图已“结束编辑”)。我还缺少其他一些基本点吗?
I use a view-based NSOutlineView
to display and select hierarchically structured items for a scientific application.
Each row in the outline column represents an item, signified by an item-specific icon (all the same in the picture), a checkbox that shows if the item is selected, and the name of the item. I need the icon, the checkbox and the name to appear in the same cell, hence I am using a view-based NSOutlineView
.
I have implemented the NSOutlineViewDataSource
protocol to supply data to the the outline view.
The method outlineView:objectValueForTableColumn:byItem:
supplies a custom object that has the properties BOOL selected
and NSString *name
.
My custom table cell view in IB is composed as follows:
I bound the check box value to objectValue.selected
and the label value to objectValue.name
.
As I hoped, the outline view displays nicely the name and selection state supplied by the objectValue.
However, if I change the state of the check box, the method outlineView:setObjectValue:forTableColumn:byItem:
that is defined in the NSOutlineViewDataSource protocol is not triggered in my dataSource to supply the newly changed object value. Note that if I don't use a custom view for the cell this works.
I checked whether the table cell view's objectValue.selected
actually gets changed when clicking the check box by inserting an NSLog statement into the setSelected
method of the object that is passed as objectValue
. The selected
member changes state correctly.
How do I propagate the change of the objectValue
back to my dataSource's model? I have checked the NSOutlineView's delegate methods, but can't find a way to signal that the cell view's objectValue was changed by my check box (i.e., that the cell view has "ended editing"). Is there some other fundamental point I am missing?
发布评论
评论(2)
setObjectValue 不适用于基于视图的视图:
来自 header::
setObjectValue doesnt work for view based ones:
from header::
我能够通过创建
NSTableCellView
的子类,使其成为所包含的NXTextField
的委托,并使用编辑后的值来更新NSTableCellView
来解决此问题code> 的对象值。I was able to solve this problem by creating a subclass of
NSTableCellView
, making it the delegate of the containedNXTextField
, and using the edited value to updateNSTableCellView
's object value.