I want to stop the modality when the user clicks the red close button in NSWindowController.
The NSWindowController has OK and Cancel buttons.
- (IBAction)okButtonClicked:(id)sender { [NSApp stopModalWithCode:NSOKButton]; [self.window close]; } - (IBAction)cancelButtonClicked:(id)sender { [NSApp stopModalWithCode:NSCancelButton]; [self.window close]; }
And when I press the red close button, the window closes and the modal value does not stop. I found the windowWillClose: function.
- (void)windowWillClose:(NSNotification *)notification { if ([NSApp modalWindow] == self.window) [NSApp stopModal]; }
but
if ([NSApp runModalForWindow:myWindowController.window] != NSOKButton) return;
Even if I click OK, the windowWillClose: function is called and the runModalForWindow: function always returns NSCancelButton.
I can add a member variable to myWindowController as a result of modality.
But I think that there will be another general way to solve this problem.
I want to make an easy way.
source share