TheNerdyCoder
TheNerdyCoder

Reputation: 184

Terminating an application when closing the window

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.

Upvotes: 4

Views: 499

Answers (2)

Amit Singh
Amit Singh

Reputation: 2644

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.

Upvotes: 1

Anoop Vaidya
Anoop Vaidya

Reputation: 46563

Yes you can do with Mac OSX applications.

You need to implement this method in your AppDelegate class

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

Upvotes: 23

Related Questions