• 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: Can't get setDelegate to work on NSMenu attached to NSStatusItem
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Can't get setDelegate to work on NSMenu attached to NSStatusItem


  • Subject: Re: Can't get setDelegate to work on NSMenu attached to NSStatusItem
  • From: Andy Lee <email@hidden>
  • Date: Wed, 04 Mar 2009 12:48:49 -0500

On Mar 3, 2009, at 2:30 PM, Mark D. Gerl wrote:
SampleController *menuController =
[[[SampleController alloc] init] autorelease];

[menu setAutoenablesItems:NO];

NSMenuItem *item = [menu addItemWithTitle:@"Quit"
action:@selector(menuHandler:) keyEquivalent:@""]; [item setTarget:menuController];
[item setTag:9];
[item autorelease];

// *** DOING this causes the menu to NOT pop down ***
[menu setDeligate:menuController];

[statusItem setMenu:menu];

Nick Zitzmann has already pointed out that item is overreleased, so it is probably being dealloc'ed prematurely. I suspect this in turn is causing menuController (which is autoreleased) to be dealloc'ed prematurely, since item had the only strong reference to it. Note that delegates are not retained, so [menu setDelegate:menuController] does not retain menuController and in fact is now holding on to a bad pointer. I'm only guessing here, but you can test the theory by putting a breakpoint or NSLog in SampleController's dealloc method.


Do you see any error messages in the Run console?

--Andy

_______________________________________________

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: 
 >Can't get setDelegate to work on NSMenu attached to NSStatusItem (From: "Mark D. Gerl" <email@hidden>)
 >Re: Can't get setDelegate to work on NSMenu attached to NSStatusItem (From: Nick Zitzmann <email@hidden>)
 >Re: Can't get setDelegate to work on NSMenu attached to NSStatusItem (From: "Mark D. Gerl" <email@hidden>)

  • Prev by Date: Sheet not ending
  • Next by Date: Re: Sheet not ending
  • Previous by thread: Re: Can't get setDelegate to work on NSMenu attached to NSStatusItem
  • Next by thread: Re: Can't get setDelegate to work on NSMenu attached to NSStatusItem (SOLVED)
  • Index(es):
    • Date
    • Thread