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: "Mark D. Gerl" <email@hidden>
- Date: Tue, 3 Mar 2009 14:30:57 -0500
On Mar 3, 2009, at 11:52 AM, Nick Zitzmann wrote:
Can you please show your code? I've done this before, and it worked
when I tried it.
SURE, see below. I should point out that I've also tried implementing
other delegate methods, with no luck. And, I've tried setting the
menu's delegate AFTER setting the menu for the NSStatusItem - with the
same results.
@interface SampleController : NSObject {
// nothing here
}
-(void)menuHandler:(id)sender;
- (void)menuNeedsUpdate:(NSMenu *)menu;
@end
@implementation SampleController
-(void)menuHandler:(id)sender
{
// works fine
}
-(void)menuNeedsUpdate:(NSMenu *)menu // delegate method
{
// *** NEVER GETS HERE ****
}
@end
// put this wherever...
NSStatusItem statusItem=[[[NSStatusBar systemStatusBar]
statusItemWithLength:NSVariableStatusItemLength] retain];
[statusItem setHighlightMode:YES];
[statusItem setTitle:@"XYZ"];
[statusItem setMenu:theMenu];
[statusItem setEnabled:YES];
// build NSMenu by HAND
NSMenu *menu = [[[NSMenu alloc] initWithTitle:@"abc"] autorelease];
if (menu != NULL)
{
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];
}
Thanks,
M
--
Mark D. Gerl, Multimedia Design Group, <mailto:email@hidden>
_______________________________________________
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