Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Stopping modal when window is closed (Cocoa)

I am currently displaying a modal window by using this code:

[[NSApplication sharedApplication] runModalForWindow:mainWindow];

However, when I close this window, the other windows are still inactive. How do I run the stopModal method when the window is closed using the "red x"?

Thank you,

Michael

like image 785
Michael Avatar asked Jan 05 '10 23:01

Michael


1 Answers

You can create a delegate for the window and have it respond to either the
-(void)windowWillClose:(NSNotification *)notification or the
- (void)windowShouldClose:(NSNotification *)notification methods like so:

- (void)windowWillClose:(NSNotification *)notification {
   [[NSApplication sharedApplication] stopModal];
}

See Mac Dev Center: NSWindowDelegate Protocol Reference

like image 51
Randall Avatar answered Oct 07 '22 13:10

Randall