I want to close my application when the last main window closes. I cannot use applicationShouldTerminateAfterLastWindowClosed:
for the following reasons:
You may still use applicationShouldTerminateAfterLastWindowClosed:
Write it to return NO
until the moment you first show the main window. Make it return YES
from then onwards.
Instances of NSPanel don't count towards open windows. Thus this will work if your help window is a NSPanel.
What you need to do is set you controlling class as the delegate of your main window, and then using NSNotificationCenter add an observer with the NSWindowWillCloseNotification with yourWindow being the object. So like this
NSNotificationCenter *c = [NSNotificationCenter defaultCenter];
[c addObserver:self selector:@selector(yourSelector) name:NSWindowWillCloseNotification object:yourWindow];
Now, the method yourSelector will be called when the main window is close, so in that method just have something like exit(0);
For more info go here and look at windowWillClose
精彩评论