NSTableView Right Clicked Row Index

后端 未结 5 1319
太阳男子
太阳男子 2020-12-29 09:16

I\'m looking for a way to get right-clicked row index from NSTableView but I can\'t find any delegate methods or class attributes for it. Any suggestion is appr

5条回答
  •  忘掉有多难
    2020-12-29 09:29

    Just select row on right-click by implementing menuForEvent: in NSTableView subclass:

    @implementation MyTableView
    
    - (NSMenu *)menuForEvent:(NSEvent *)theEvent
    {
        int row = [self rowAtPoint:[self convertPoint:theEvent.locationInWindow fromView:nil]];
        if (row == -1) 
            return nil;
        if (row != self.selectedRow)
            [self selectRowIndexes:[NSIndexSet indexSetWithIndex:row] byExtendingSelection:NO];
        return self.menu;
    }
    
    @end
    

提交回复
热议问题