user3240231
user3240231

Reputation: 23

terminate an application when close button is clicked

I am developing a mac application in Xcode 5.1. I would like to terminate the application when the close button is clicked inside the application. Check the link for the image.

The link is as follows http://tinypic.com/r/2yn070h/8.

There is a red button on top of the window. When I click the red button the application has to be terminated. The code for termination is as follows

[NSApp terminate:self];

Upvotes: 1

Views: 1834

Answers (2)

lee
lee

Reputation: 8115

To exit your app use command exit(0).

Upvotes: -2

Merlevede
Merlevede

Reputation: 8180

The only thing you have to do is implement this method in your AppDelegate:

- (BOOL)applicationShouldTerminateAfterLastWindowClosed:(NSApplication *)theApplication {
    return YES;
}

Upvotes: 5

Related Questions