I’m working with storyboard and this is the code I have below.
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification {
// Insert code here to initialize your application
NSStatusItem *status_item = [[NSStatusBar systemStatusBar] statusItemWithLength: -1];
[status_item setMenu:_menu_bar_item];
status_item.button.image = [NSImage imageNamed:@"MenuBarIcon"];
status_item.button.imagePosition = NSImageLeft;
status_item.button.title = @"foo";
status_item.button.toolTip = @"bar";
[status_item setVisible:true];
}
The status item does show in the menu bar for like a frame and then instantly dissapears. I’ve tried it with and without the image and I can’t get it to show longer than a split second before it just vanishes. Does anyone know what causes this and how to prevent it?
>Solution :
You are creating the object and then you throw it away.
You need a strong reference for example a property
@property (strong) NSStatusItem *status_item;
and then
status_item = [[NSStatusBar systemStatusBar] statusItemWithLength: -1];