Instance Method

stopModalWithCode:

Stops a modal event loop, allowing you to return a custom result code.

Declaration

- (void)stopModalWithCode:(NSModalResponse)returnCode;

Parameters

returnCode

The result code you want returned from the runModalForWindow: or runModalSession: method. The meaning of this result code is up to you.

Discussion

This method should always be paired with a previous invocation of runModalForWindow: or beginModalSessionForWindow:. When runModalForWindow: is stopped with this method, it returns the given returnCode. In macOS 10.9 and later, you can use this method to stop a runModalForWindow: loop outside of an event callback, such as from within a method repeatedly invoked by an NSTimer object or a method running in a different thread.

See Also

Running a Modal Window

- runModalForWindow:

Starts a modal event loop for the specified window.

- stopModal

Stops a modal event loop.

- abortModal

Aborts the event loop started by runModalForWindow: or runModalSession:.

- beginModalSessionForWindow:

Sets up a modal session with the given window and returns a pointer to the NSModalSession structure representing the session.

- runModalSession:

Runs a given modal session, as defined in a previous invocation of beginModalSessionForWindow:.

modalWindow

The modal window displayed by the app.

NSModalResponse

A set of button return values for modal dialogs.

NSModalSession

Variables of type NSModalSession point to information used by the system between NSApplication’s beginModalSessionForWindow: and endModalSession: messages.

NSModalPanelRunLoopMode

A run loop should be set to this mode when waiting for input from a modal panel, such as NSSavePanel or NSOpenPanel.