Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's the correct way to capture the return code of an alert sheet for OS X 10.9+?

According to Apple's documentation, it appears that the only non-deprecated method for displaying an alert sheet is beginSheetModalForWindow:completionHandler:, where completionHandler block takes an argument of NSModalResponse-type. NSModalResponse is an enum with only 3 possible values: NSModalResponseStop, NSModalResponseAbort and NSModalResponseContinue. So how do I know which button on an alert sheet was clicked by the user?

like image 376
Ethan Avatar asked Oct 02 '14 22:10

Ethan


People also ask

How to assert that correct status code is returned?

Once the status code is received, it is compared with the expected value of 200. // Assert that correct status code is returned. Assert.assertEquals (statusCode /*actual value*/, 200 /*expected value*/, "Correct status code returned");

What is an example of alert box?

Otherwise, it will show a warning message that the age is below 18 years. This warning message is the 'Alert Box'. Another example is suppose a user is required to fill the form in which some mandatory fields are required to enter some text, but the user forgets to provide the input.

Where can I find the error message for return codes?

The error message is displayed at the command prompt and is identified in the ScanState, LoadState, or USMTUtils log files to help you determine why the return code was received.

What is an alert in JavaScript?

It consists of the information that we want to show to the users. Let's see some examples of the JavaScript alert () method. In this example, there is a simple alert dialog box with a message and an OK button. Here, there is an HTML button which is used for displaying the alert box.


1 Answers

The result code is not really an enum in the sense that it's not restricted to just the values of the NSModalResponse type. The enum is only used to define some of the possible values.

See the documentation for the -addButtonWithTitle: method of NSAlert, for example, which explains the response codes generated from the added button: NSAlertFirstButtonReturn for the first, NSAlertSecondButtonReturn for the second, NSAlertThirdButtonReturn for the third, and NSAlertThirdButtonReturn + n for subsequent buttons.

See also the documentation for the -runModal method:

If you use alertWithMessageText:defaultButton:alternateButton:otherButton:informativeTextWithFormat: to create an alert, the following constants are used to identify the button used to dismiss the alert: NSAlertDefaultReturn, NSAlertAlternateReturn, and NSAlertOtherReturn. Otherwise, the constants used are the ones described in “Button Return Values.”

That's the same rule that applies for the response code passed to the completion handler you supply to -beginSheetModalForWindow:completionHandler:.

like image 146
Ken Thomases Avatar answered Sep 23 '22 10:09

Ken Thomases