I'm trying to create a simple menu in the System Status Bar using code only. I'm not receiving any compilation or runtime errors but I see no effect at all.
- (void)awakeFromNib
{
NSMenu *stackMenu = [[NSMenu alloc] initWithTitle:@"Status Menu"];
NSMenuItem *soMenuItem =
[[NSMenuItem alloc] initWithTitle:@"Status Menu Item" action:nil keyEquivalent:@"S"];
[soMenuItem setEnabled:YES];
[stackMenu addItem:soMenuItem];
statusItem = [[[NSStatusBar systemStatusBar]
开发者_开发问答 statusItemWithLength:NSVariableStatusItemLength]
retain];
[statusItem setMenu:stackMenu];
}
I don't believe the NSStatusItem
will implicitly take on the title
of the NSMenu
associated with it (which is what I am guessing you want to happen.) Try explicitly setting the NSStatusItem
's title
(and/or its image
).
e.x.
[statusItem setTitle:[stackMenu title]];
精彩评论