Cocoa 如何在NSOutlineView中将NSTableRow子类化
要更改Cocoa 如何在NSOutlineView中将NSTableRow子类化,cocoa,nstableview,Cocoa,Nstableview,要更改NSOutlineView侧栏高亮显示颜色,NSTableRow需要使用覆盖函数DrawSelectionDirect子类化。当代码中当前没有对NSTableRow的公开引用时,这怎么可能呢 func outlineView(outlineView: NSOutlineView, viewForTableColumn: NSTableColumn?, item: AnyObject) -> NSView? { } 也许有可能使用一个更简单的解决方案来强调属性 func outl
NSOutlineView
侧栏高亮显示颜色,NSTableRow
需要使用覆盖函数DrawSelectionDirect
子类化。当代码中当前没有对NSTableRow
的公开引用时,这怎么可能呢
func outlineView(outlineView: NSOutlineView, viewForTableColumn: NSTableColumn?, item: AnyObject) -> NSView? {
}
也许有可能使用一个更简单的解决方案来强调
属性
func outlineViewSelectionDidChange(notification: NSNotification){
let selectedIndex = notification.object?.selectedRow
let object:AnyObject? = notification.object?.itemAtRow(selectedIndex!)
notification.object?.rowViewAtRow(selectedIndex!, makeIfNecessary: false)?.emphasized = false
outlineView.deselectRow(selectedIndex!)
就像你用的
func outlineView(outlineView: NSOutlineView, viewForTableColumn: NSTableColumn?, item: AnyObject) -> NSView? {...}
你可以用
func outlineView(_ outlineView: NSOutlineView, rowViewForItem item: AnyObject) -> NSTableRowView? {...}
用于行视图
以下是您的操作方法:
子类NSTableRowView
并实现DrawSelectionDirect:
以自定义子类的外观
通过在rowViewForItem:
您可以看到如何在此方法中返回视图
由于您仅覆盖DrawSelectionDirect:所有其他功能仍然可用。因此,您不必做任何其他事情。就像您使用
func outlineView(outlineView: NSOutlineView, viewForTableColumn: NSTableColumn?, item: AnyObject) -> NSView? {...}
你可以用
func outlineView(_ outlineView: NSOutlineView, rowViewForItem item: AnyObject) -> NSTableRowView? {...}
用于行视图
以下是您的操作方法:
子类NSTableRowView
并实现DrawSelectionDirect:
以自定义子类的外观
通过在rowViewForItem:
您可以看到如何在此方法中返回视图
由于您仅覆盖DrawSelectionDirect:所有其他功能仍然可用。因此,您不必做任何其他事情。谢谢Max。我如何在保持现有行为的同时实现此方法?您对现有行为的意思是什么?谢谢Max。我如何在保持现有行为的同时实现此方法?您对现有行为的意思是什么?