View-based NSOutlineview selection gradient

。_饼干妹妹 提交于 2019-12-03 16:07:21

Are you doing any custom drawing that could be messing with things? As far as I can tell all the selection drawing is handled for you normally, check out the TableViewPlayground example (not Source-list style by default but that's an easy change to the XIB).

But failing that, according to the Mac OS X 10.7 doc entry on highlightSelectionInClipRect:

Note: This method should not be subclassed or overridden for a view-base table view. Instead, row drawing customization should be done by subclassing NSTableRowView.

So I think (I haven't tried any of this) like you'd want to subclass NSTableRowView, override drawSelectionInRect: (there's an example in TableViewPlayground, and draw your selection. You could check for the app being active with [NSApp active] or maybe use the self.emphasized property like the example does.

You'd then return one of your custom NSTableRowViews in the NSOutlineViewDelegate protocol method (10.7 only!): (NSTableRowView *)outlineView:(NSOutlineView *)outlineView rowViewForItem:(id)item

Hope this works/helps!

I should note that TableViewPlayground example uses the outlineView:viewForTableColumn:item: delegate method by default and does everything with NSTableViewCells, but if you add the rowViewForItem method I mention above it is called. So I'm guessing you could use it to return a view for each row in it's entirety.

Thanks, with your hint I was able to solve the problem quite easily. I subclassed NSTableRowView and overwrote -(BOOL) isEmphasized to always return true.

I then implemented -(NSTableRowView *)outlineView:(NSOutlineView *)outlineView rowViewForItem:(id)item in my OutlineViews delegate to return a item specific instance of my subclass by calling ClbTableRowView *result = [outlineView makeViewWithIdentifier:identifier owner:self];

Edit: Besides that, there also seems to be a pretty hidden way of using the custom NSTableRowView subclass by dropping a new NSView Object into the the OutlineView in Interface Builder. Then set the views class to your subclass and give it a userinterface item identifier of "NSTableViewRowViewKey", according to the Apple documentation.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!