我想处理NSOutlineView中的复选框点击。 复选框是NSButtonCell类型的复选框单元格。 我可以在以下位置设置初始状态:
optional func outlineView(_ outlineView: NSOutlineView,
willDisplayCell cell: AnyObject,
forTableColumn tableColumn: NSTableColumn?,
item item: AnyObject)
现在,当复选框的状态发生变化时,如何执行函数? 我搜索了互联网,但我找不到。
答案 0 :(得分:1)
您必须重新加载与复选框单元格对应的项目。请查看此API https://developer.apple.com/library/mac/documentation/Cocoa/Reference/ApplicationKit/Classes/NSOutlineView_Class/#//apple_ref/doc/uid/20000110-SW7
答案 1 :(得分:0)
我发现这是从表中设置值:
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)