Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

NSStatusItem dissapears instantly after launching application

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?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>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];
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading