How to make a Cocoa applicaion quit when the main window is closed? Without that you have to click on the app icon and click quit in the menu.
+7
A:
You can implement applicationShouldTerminateAfterLastWindowClosed:
to return YES in your app's delegate. But I would think twice before doing this, as it's really unusual on the Mac outside of small "utility" applications like Calculator and most Mac users will not appreciate your app behaving so strangely.
Chuck
2010-05-28 02:43:43
+1
A:
You should have an IBOutlet to your main window. For Example: IBOutlet NSWindow *mainWindow;
- (void)awakeFromWindow {
[mainWindow setDelegate: self];
}
- (void)windowWillClose:(NSNotification *)notification {
[NSApp terminate:self];
}
If this does not work you should add an observer to your NSNotificationCenter for the Notification NSWindowWillCloseNotification. Don't forget to check if the right window is closing.
papr
2010-05-28 06:06:14