Re: Contextual menu on NSOutlineView without subclassing
Re: Contextual menu on NSOutlineView without subclassing
- Subject: Re: Contextual menu on NSOutlineView without subclassing
- From: David Spooner <email@hidden>
- Date: Sun, 7 Oct 2007 12:53:23 -0600
You can override -menuForEvent: in a category of either NSTableView or
NSOutlineView, taking advantage of the fact that neither class
currently overrides NSView's implementation.
@implementation NSOutlineView(MyExtensions)
- (NSMenu *) menuForEvent:(NSEvent *)event
{
id delegate = [self delegate];
if ([delegate
respondsToSelector:@selector(extendMenu:forEvent:inOutlineView:)]) {
NSMenu *menu = [[[NSMenu alloc] init] autorelease];
[delegate extendMenu:menu forEvent:event inOutlineView:self];
return menu;
}
return [super menuForEvent:event];
}
@end
Of course this technique may break in a future release...
dave
is there an easy way to implement a contextual menu for an
NSTableview/NSOutlineView without subclassing? (a menuForEvent
delegate method would be fantastic).
_______________________________________________
Cocoa-dev mailing list (email@hidden)
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:
This email sent to email@hidden