Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

Blakeasd

macrumors 6502a
Original poster
Dec 29, 2009
643
0
Hello,
I am writing a Cocoa application and I am running into a problem, when closing the about box to my app the application terminates. I call the following method so that when my main window closes the app terminates:
Code:
-(BOOL)applicationShouldTerminateAfterLastWindowClosed:(NSApplication *)sender{

    return YES;

}

The main window to my app is an HUD panel so I think this may be causing the problem
Any Solutions? I would leave it alone, but my app is rejected because Apple considers it to be a bug.
 
I'm guessing what's happening is since your window is an NSPanel it is not registered as a main window, so after the About box closes, it doesn't have a main window anymore and terminates. You could try subclassing NSPanel and overriding canBecomeMainWindow and return YES, then use this subclass in your nib.
 
Because your "main" window is a NSPanel, it's responding NO to canBecomeMainWindow. In Cocoa terms, you don't have a main window. That's why applicationShouldTerminateAfterLastWindowClosed: is being sent to your application delegate when the user closes the about box. You're unconditionally responding with YES, so you're app terminates.

You have 2 choice.

a) Subclass NSPanel so canBecomeMainWindow responds YES. That way you will have a main window and your application delegate won't be sent applicationShouldTerminateAfterLastWindowClosed: when the about box is closed.

b) Or check to see if you're HUD panel is open in applicationShouldTerminateAfterLastWindowClosed: and respond NO if it is.

EDIT: What kainjow said. :)
 
I subclassed NSPanel and did the following:
Code:
-(BOOL)canBecomeMainWindow{

    return YES;

}
This doesn't seem to work though :(
 
You're right.

I looked at the docs for applicationShouldTerminateAfterLastWindowClosed and it says:
It sends this message regardless of whether there are still panels open. (A panel in this case is defined as being an instance of NSPanel or one of its subclasses.)

So you need to handle this somehow, possibly like this:
Code:
- ([color=#aa0d91]BOOL[/color])applicationShouldTerminateAfterLastWindowClosed:([color=#5c2699]NSApplication[/color] *)theApplication
{
    [color=#aa0d91]for[/color] ([color=#5c2699]NSWindow[/color] *win [color=#aa0d91]in[/color] [[color=#5c2699]NSApp[/color] [color=#2e0d6e]windows[/color]]) {
        [color=#aa0d91]if[/color] ([win [color=#2e0d6e]isVisible[/color]]) {
            [color=#aa0d91]return[/color] [color=#aa0d91]NO[/color];
        }
    }
    [color=#aa0d91]return[/color] [color=#aa0d91]YES[/color];
}
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.