Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Allow app to terminate while sheet is visible

Tags:

macos

cocoa

I have a sheet that attaches to my main window. This is a login sheet that should not allow any interaction with the app until it is finished (modal as is the default). HOWEVER, I would like the user to be able to terminate the app. IE, they realize they need a login, give up and want to close the app. The default behavior is to play NSBeep and keep running. How can I override this?

like image 867
David Beck Avatar asked Feb 25 '23 18:02

David Beck


2 Answers

Beginning with 10.6 you can control whether the modal sheet should prevent the application from terminating. This should do it:

[myModalSheet setPreventsApplicationTerminationWhenModal:NO];
like image 178
Salaryman Avatar answered Mar 03 '23 23:03

Salaryman


It sounds like the root of the problem is that you're relying on the sheet to prevent interaction with the rest of the app. You're effectively storing application state information (logged in/not logged in) in a view, and that's not a good plan.

The sheet should allow the user to enter their login information, and the login sheet's controller should update the app's state as the info is entered. If you take this approach, the application won't allow the user to do anything that requires a login until the login process is actually complete, whether the sheet is there or not.

like image 30
Caleb Avatar answered Mar 03 '23 23:03

Caleb