Re: Can't get setDelegate to work on NSMenu attached to NSStatusItem
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