Question

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];
}
Was it helpful?

Solution

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]];
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top