Search code examples
objective-cmacoscocoansoutlineviewappkit

Custom selection style for view based "Source List" NSOutlineView


I'm using a view based NSOutlineView that has it's selectionHighlightStyle set to NSTableViewSelectionHighlightStyleSourceList.

I want to overwrite the selection style (background) for certain rows and draw a different color/gradient.

What I tried so far is creating a custom NSTableRowView and returning it via outlineView:rowViewForItem:. I verified that my custom row views are created and returned by the outline view delegate. However, none of the methods I'm overwriting in the custom row view are being called.

I tried to overwrite drawBackgroundInRect:, drawSelectionInRect:, drawSeparatorInRect: and even drawRect:. None of those are called, ever.

I'm suspecting the outline view to be doing some custom "magic" when it's set to the source list style, but I've not found anything in the documentation that indicates that a custom NSTableRowView wouldn't be honored at all in this case.


Solution

  • Are you using Yosemite? From Apple's document Adopting Advanced Features of the new UI in Yosemite

    When selectionHighlightStyle == NSTableViewSelectionHighlightStyleSourceList • Selection is now a special blue material that does behind window blending - The material size and drawing can not be customized

    If you set it to NSTableViewSelectionHighlightStyleRegular and override the drawRect, it should work.