fff
fff

Reputation: 25

How do I subclass NSTableRow in NSOutlineView

To change the NSOutlineView sidebar highlight colour, NSTableRow needs to be subclassed with an override func drawSelectionInRect. How is this possible when there is currently no exposed reference to NSTableRow in code?

func outlineView(outlineView: NSOutlineView, viewForTableColumn: NSTableColumn?, item: AnyObject) -> NSView? {

}

Perhaps there is potential in using a simpler solution with the emphazised property

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!)

Upvotes: 0

Views: 560

Answers (1)

mangerlahn
mangerlahn

Reputation: 4966

Just as you use

func outlineView(outlineView: NSOutlineView, viewForTableColumn: NSTableColumn?, item: AnyObject) -> NSView? {...}

you can use

func outlineView(_ outlineView: NSOutlineView, rowViewForItem item: AnyObject) -> NSTableRowView? {...} 

for rowViews.

Here is how you do it:

  1. Subclass NSTableRowView and implement drawSelectionInRect: to customize the appearance of your subclass.

  2. Make sure that your outlineView knows about your subclass by returning it in rowViewForItem: You can see how to return the view in this method here.

Since you only override drawSelectionInRect: every other functionality will still be available. So you don't have to do anything else.

Upvotes: 2

Related Questions