Reputation: 1509
I'm new too Xcode (5.1.1) and Mac's (OS X) and I'm trying to get my app to close when the red close button is pressed. I am using the below code to try and do it in AppDelegate.m
- (void)windowWillClose:(NSNotification *)aNotification {
[NSApp terminate:self];
}
But all this seems to do is close the window, the app itself is still running and the icon remains in the dock. Though clicking the icon does nothing and neither does launching the app again (it seems to think it is still running). I have to force shut down in order to launch the app again.
Any help would be great thanks.
Upvotes: 0
Views: 1112
Reputation: 1
if you don't want to quit the application, you should do this :
- (BOOL)applicationShouldTerminateAfterLastWindowClosed:(NSApplication *)sender {
return NO;
}
Upvotes: 0
Reputation: 6128
If shutting down the application when the last window closes is acceptable you can use the following method in your app delegate.
- (BOOL)applicationShouldTerminateAfterLastWindowClosed:(NSApplication *)sender
{
return YES;
}
Upvotes: 4