I'm a little bit new to Objective-c with xCode, and I would like to know something. Is there a way to terminate an application when the red circle in the left of the window is clicked? Like on the calculator.
Asked
Active
Viewed 478 times
4
-
Make your question more clear. Are you talking about a cocoa application? Specify the appropriate tag. – Rakesh Mar 02 '13 at 15:49
-
@Rakesh Yes, a Cocoa application. Sorry for any unclarity – TheNerdyCoder Mar 02 '13 at 15:51
-
Np. You have a working solution below. You can accept it as answer ,if you feel its good enough. Good luck. – Rakesh Mar 02 '13 at 15:55
-
+1 for question on osx :) . I want to build SO database powerfull enough even for osx. That is why I upvote for osx problem. – Anoop Vaidya Mar 02 '13 at 16:01
-
1@AnoopVaidya Thanks :) OS X is truly awesome. – TheNerdyCoder Mar 02 '13 at 16:03
-
Try This.. -(IBAction)closeProgram:(id)sender{ exit(0); } – Dipendra Mar 03 '13 at 18:42
2 Answers
23
Yes you can do with Mac OSX applications.
You need to implement this method in your AppDelegate class
- (BOOL)applicationShouldTerminateAfterLastWindowClosed:(NSApplication *)sender{
return YES;
}

Anoop Vaidya
- 46,283
- 15
- 111
- 140
-
Why down vote? Targeting me?? I got three in short span of time, and then one was reverted. – Anoop Vaidya Apr 02 '13 at 13:13
-
+1 from my side but this one is really nice answer, i mean like most of those one liner which go hight in the chart. – rptwsthi May 19 '13 at 07:57
1
If you want terminate the app when closing the window. Please implement the following appdelegate method.
- (BOOL)applicationShouldTerminateAfterLastWindowClosed:(NSApplication *)sender
{
return YES;
}
If you want do not terminate your app, just set the return "NO".
I hope that your problem will be resolved with this solution.

Rakesh
- 3,370
- 2
- 23
- 41

Amit Singh
- 2,644
- 21
- 20