• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag
 

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Contextual menu on NSOutlineView without subclassing
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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


References: 
 >Re: Contextual menu on NSOutlineView without subclassing (From: David Spooner <email@hidden>)

  • Prev by Date: NSDocument, setFileURL:
  • Next by Date: Re: [question] Checking for duplicate entries in NSMutableArray
  • Previous by thread: Re: Contextual menu on NSOutlineView without subclassing
  • Next by thread: Re: ObjC vs C++ (was: Is ZLib available in Cocoa?)
  • Index(es):
    • Date
    • Thread