I have created a status bar only application for the Mac OS X. Something like that http://d.pr/i/Covi . I created it by this tutorial http://cocoatutorial.grapewave.com/2010/01/creating-a-status-bar-application/ . Now I have a question: how I can show window by clicking “About” menu item? I trying that:
#import "IGAppDelegate.h"
#import "IGAboutWindowController.h"
@implementation IGAppDelegate
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification
{
// Insert code here to initialize your application
}
- (void)awakeFromNib {
_statusItem = [[NSStatusBar systemStatusBar] statusItemWithLength:NSVariableStatusItemLength];
[_statusItem setMenu:_menu];
[_statusItem setTitle:@"LeoHelper"];
[_statusItem setHighlightMode:YES];
}
#pragma mark - Actions
- (IBAction)quit:(id)sender {
[NSApp terminate:self];
}
- (IBAction)about:(id)sender {
IGAboutWindowController *aboutController = [[IGAboutWindowController alloc] init];
[aboutController showWindow:self];
}
@end
I’m going to make a guess that you are using Automatic-Reference-Counting (ARC). If you are, then here’s what’s going to happen in the
about:method:You first create a local instance of
IGAboutWindowController, then tell it to show its window. This will show the window on the screen, but, if your project is using ARC, the window will then immediately disappear. The reason for that is that as soon as theabout:method ends, your local instance of theIGAboutWindowControllerwill be automatically deallocated, and as a result, its window will be removed from the screen.To successfully implement this
about:method in an ARC-managed project, you should define theaboutControlleras an instance variable of yourIGAppDelegateclass like this:Then implement your
about:method like this: