NSTableView: blue outline on right-clicked rows

强颜欢笑 提交于 2019-12-04 05:52:10
Nicholas Riley

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

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