Search code examples
objective-ccocoanstableviewright-click

Show contextual menu on ctrl-click/right-click on header of NSTableView


I'm searching for an elegant way to detect a right-click/ctrl-click on the header of an NSTableView.

When the right click occurs, I want to display an contextual menu.

- (NSMenu *)menuForEvent:(NSEvent *)

detects only right clicks in the table - not in the header of the table.

thanks for your help.


Solution

  • Get the NSTableHeaderView from the NSTableView and set it's menu.

    [[myTableView headerView] setMenu:aMenu];