Cool About box, but it's not key (won't close)


I have the most cool about box. Well, it’s an image well and a photoshop tiff.

It shows up when asked by the “About Raiseman” menu item.

The thing is, it’s not the key window, so I can’t simply hit escape to close it. I gotta click on the window first, then hit it’s close box or esc.

Why isn’t it becoming the front key window? What do I gotta do to get it to be that? It’s driving me nuts, I’ve been using Mac programs too long to accept these little annoyances.


I’m going to guess, for now, that a lack of a controller makes this impossible, to get the About Box to be the key window. If I’m wrong, do enlighten me on how to do it.


I tried to close my About Box using escape and it too wouldn’t close, so I went searching for an answer. I read through this chapter and found a clue:


[quote]If you wanted to load a nib file without an NSWindowController, you could do it like this:

Since we aren’t using NSWindowController, there is nothing to bring the window to the front. So, I went to the Apple documentation and found a method in NSWindow that helps:

So, incorporating that into the code:

- (IBAction) showAboutPanel: (id) sender { if (!myAboutController) { myAboutController = [[AboutController alloc] init]; } BOOL successful = [NSBundle loadNibNamed: @"About" owner: myAboutController]; if (successful) [[myAboutController window] makeKeyAndOrderFront: self]; }


It is possible to implement the challenge About box using only the base NSWindowController class (i.e. not a subclass).

First off, you will need to add an outlet for an About window (an NSPanel actually) in your application delegate (or AppController):

@interface RaiseManAppDelegate : NSObject <NSApplicationDelegate> {
    NSPanel *aboutPanel;

@property (assign) IBOutlet NSPanel *aboutPanel;

- (IBAction)showAboutPanel:(id)sender;


The showAboutPanel: method is very similar to the example posted by ramjet:

@synthesize aboutPanel;

- (IBAction)showAboutPanel:(id)sender
    // Is aboutPanel nil?
    if (!aboutPanel) {
        BOOL success = [NSBundle loadNibNamed:@"About" owner:self];
        if (!success) {
            NSLog(@"Ooops! Bundle was not loaded!");
    [aboutPanel makeKeyAndOrderFront:self];

Of course, the above assumes you’ve also:

  • connected the “About RaiseMan” MainMenu item to the AppDelegate’s showAboutPanel: action method
  • created an “About.xib” interface file containing the About panel, with its File’s Owner set to the AppDelegate
  • connected the About panel to the File’s Owner aboutPanel outlet

And that’s basically it. The About Box should close when hitting escape.