Reputation: 800
I'm trying to make a Cocoa application that's pretty simple. I have three windows with three messages on them, that's all there is to it. What I'm trying to do is this:
The user runs the app, the app icon appears in the menu bar and that's all that happens, no menu and no dock icon
Then, the user can click the MenuBar Icon and have a dropdown list and choose from the three available messages.
I know it's useless, but this is literally my first application and I can't figure out how to get NSStatusItem to work properly...
I've looked around and found some tutorials but I can't seem to follow any of them...any help?
Upvotes: 15
Views: 6580
Reputation: 49344
LSUIElement
entry to Info.plist file and set it to true. This won't show application in app switcher UI (cmd+tab) as well.NSStatusBar
and NSStatusItem
documentation and using example code there:.
// this one is taken from apple documentation
- (void)activateStatusMenu {
NSStatusBar *bar = [NSStatusBar systemStatusBar];
theItem = [bar statusItemWithLength:NSVariableStatusItemLength];
[theItem retain];
[theItem setTitle: NSLocalizedString(@"Tablet",@"")];
[theItem setHighlightMode:YES];
[theItem setMenu:theMenu];
}
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification {
[self activateStatusMenu];
}
Update Since ARC does not allow retain
calls in the code, I managed to solve the issue by creating theItem
as __strong
instance variable of the class where the item is being created.
Upvotes: 19