Reputation: 64864
I have an interface builder (nib) file with 4 NSTableView.
All of them have the same NSMenu as context menu (I've wired each table to the same menu component).
There is only a menu item inside the menu and it has as target function:
-(IBAction)addRemoveItem:(id)sender
I can easily get the NSMenuItem from the function parameter, and therefore the NSMenu. But how do I get the table? I cannot set it as delegate, because I'm using the same menu with multiple tables.
Upvotes: 1
Views: 651
Reputation: 90681
One approach would be to query each table view for its clickedRow
. The one which has a value other than -1 is the one which was clicked on.
Another approach might be to use a custom subclass of NSTableView
for each table view. In your custom subclass, override -menuForEvent:
. Call through to super. If that returns a menu, report to some other object that this table is showing a contextual menu, then return that menu. You could extend the delegate protocol to do the reporting or you could post a notification.
Upvotes: 1
Reputation: 2251
1) What is the "responder chain" i.e. in what order do the responders fire?
i.e. someTopView (does not accept first responder)->anotherView(handles responder)
.
n.b. a classic example if this is if you place a NSControl inside a NSView. Despite NSControl inheriting from NSView, it handles the first responder i.e. when you click on it, it handles it rather than the view below it.
2) Have you looked up "NSView hittest" which checks the position of the mouse when actions are fired...
Upvotes: 0