Abcd Efg Abcd Efg - 6 months ago 40
Objective-C Question

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.

Answer

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