如何在基于 NSOutlineView 的单元格中处理复选框点击

How to handle Check Box clicks in a cell based NSOutlineView

我想处理 NSOutlineView 中复选框的点击。 复选框是 NSButtonCell 类型的 Check Box Cell。 我可以将初始状态设置为:

optional func outlineView(_ outlineView: NSOutlineView,
                            willDisplayCell cell: AnyObject,
                            forTableColumn tableColumn: NSTableColumn?,
                            item item: AnyObject)

现在,当复选框的状态发生变化时,如何执行函数? 我在互联网上搜索过,但找不到。

我发现这是为了设置来自 table 的值:

DragNDropOutlineView: implementing drag and drop in an NSOutlineView

// Optional method: needed to allow editing.
- (void)outlineView:(NSOutlineView *)ov setObjectValue:(id)object forTableColumn:(NSTableColumn *)tableColumn byItem:(id)item  {
AAPLSimpleNodeData *nodeData = [item representedObject];

// Here, we manipulate the data stored in the node.
if ([[tableColumn identifier] isEqualToString:COLUMID_IS_SELECTABLE]) {
    nodeData.selectable = [object boolValue];
}

}

另一种方法是设置每个单元格的目标和操作:

optional func outlineView(_ outlineView: NSOutlineView,
                        willDisplayCell cell: AnyObject,
                        forTableColumn tableColumn: NSTableColumn?,
                        item item: AnyObject)

您必须重新加载与复选框单元格对应的项目。请看看这个APIhttps://developer.apple.com/library/mac/documentation/Cocoa/Reference/ApplicationKit/Classes/NSOutlineView_Class/#//apple_ref/doc/uid/20000110-SW7