Search code examples
objective-ccocoanstableview

NSTableView Right Clicked Row Index


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


Solution

  • While I haven't done this, I am pretty sure you can by overriding NSView's - (NSMenu*)menuForEvent:(NSEvent*)theEvent. The example in this link does a point conversion to determine the index.

    -(NSMenu*)menuForEvent:(NSEvent*)theEvent
    {
        NSPoint mousePoint = [self convertPoint:[theEvent locationInWindow] fromView:nil];
       int row = [self rowAtPoint:mousePoint];
       // Produce the menu here or perform an action like selection of the row.
    }