In my cell-based table I created an empty menu whose delegate was the
outlineView, then implemented menuNeedsUpdate:, and it didn't need to change
for view-based. I think it came from Apple sample code originally, and is
basically
NSInteger clickedRow = [outlineView clickedRow];
if (clickedRow != -1) { // -1 means empty row
item = [outlineView itemAtRow:clickedRow];
[self updateMenu:menu forItem:item];
}
and updateMenu:forItem: swaps out all of menu's contents for what that item
needs. There's also another menu with the general outlineView contents, and if
I need that one I do the same swap.
On Jun 11, 2014, at 5:55 PM, Graham Cox wrote:
> I'm having trouble getting contextual menus to work in a view-based
> NSOutlineView.
>
> I can set a menu on the whole outline view and that works, but I also need to
> have menus for each row. Setting a menu on the NSTableCellView subclass in IB
> doesn't work at all - it seems as if the menu isn't copied when the view is
> instantiated from the nib (the -menu property is nil on the view instance).
> But if I override -menu, or -menuForEvent: and return something, it is still
> not used. In fact those methods are never invoked. If I do the same on the
> NSTableRowView subclass, then the menu shows, but only if I click in areas
> that are not occupied by views within my cell view, which is not useful. If
> the table row gets the menu highlight, then the menu doesn't show (and the
> -menu method on the row isn't invoked).
>
> I did get this working in a cell-based outline view a few years ago, but with
> a view-based OV, I can't find the magic fairy dust I need. The simplest way
> would be just to set up the view's menu in IB, but it seems that's broken or
> overlooked in the OV implementation. Can anyone suggest a workaround other
> than those I've tried?
>
> --Graham
>
_______________________________________________
Cocoa-dev mailing list ([email protected])
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com
This email sent to [email protected]