I’m trying to make an app, which, when the main window isn’t visible, shows an icon in the menubar. However, I’m not sure about this code and whether it’s ok. I get no errors and no warnings but after a few app switches back and forth between my app and another eg. Twitter or Safari I get
Program received signal:
“EXC_BAD_ACCESS”.
Here is my code:
- (void)applicationDidResignActive:(NSNotification*)aNotification
{
statusItem = [[[NSStatusBar systemStatusBar]
statusItemWithLength:NSVariableStatusItemLength]
retain];
[statusItem setHighlightMode:YES];
[statusItem setEnabled:YES];
//Set menubar item's tooltip
[statusItem setToolTip:@"Nucleus"];
[statusItem setMenu:theMenu];
//Set the menubar item's title
[statusItem setTitle:[NSString stringWithString:@"N"]];
}
- (void)applicationDidBecomeActive:(NSNotification*)aNotification
{
[statusItem release];
}
I simply replaced [statusItem release]; with [[NSStatusBar systemStatusBar] removeStatusItem:statusItem]; and that worked a treat. I don’t want to completely release it as I still need it incase the user switches apps later. Thanks to @Kevin Ballard for that! 🙂