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 (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to