Re: Contextual menu on NSOutlineView without subclassing
Re: Contextual menu on NSOutlineView without subclassing
- Subject: Re: Contextual menu on NSOutlineView without subclassing
- From: Bert Torfs <email@hidden>
- Date: Sun, 7 Oct 2007 21:53:10 +0200
Wonderfull. In fact, (shame on me), I never knew you could use
categories to override behavior. Thought it was only to add methods…
Thanks,
Bert
On 07 Oct 2007, at 20:53, David Spooner wrote:
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