NSTableView: blue outline on right-clicked rows

淺唱寂寞╮ 提交于 2019-12-06 02:05:04

问题


I'm wondering how I can get rid of the blue outlines that Cocoa draws around rows in NSTableView / NSOutlineView when right-clicking on them.

NSTableView Outline http://tobidobi.com/nstableview_outline.png

It doesn't seem to be a classic "highlight" nor a "focus ring" if I'm not mistaken - so, what is it, actually?

I'm currently drawing custom NSCells completely myself - but I can't figure out how to either
* draw this outline by myself, too, or
* get rid of it, or
* at least change its colour

Any hints are very welcome! Thanks!


回答1:


Unfortunately I'm not aware of any documented way to do this, short of writing your own table view replacement.

The method to override is:

- (void)drawContextMenuHighlightForRow:(NSInteger)row;

Please file an enhancement request with Apple so you won't have to rely on undocumented methods to do what you want in future. It looks like the other two table view highlight methods were made customizable in 10.6 but this one wasn't. I've always thought it was a bit clunky looking but it's necessary to indicate what row the menu is referencing (not necessarily the same as the highlighted row).




回答2:


My NSTableView *mainTableView is not sub-classed so I got rid of it just before the contextual menu opens:

- (void)menuWillOpen:(NSMenu *)menu{
     NSInteger rightClicked = [mainTableView clickedRow];
     [mainTableView selectRowIndexes:[NSIndexSet indexSetWithIndex:rightClicked] byExtendingSelection:NO];
     [mainTableView deselectRow: rightClicked];
     [mainTableView reloadData];
    {


来源:https://stackoverflow.com/questions/4219764/nstableview-blue-outline-on-right-clicked-rows

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