Closing all windows when closing one of them
Closing all windows when closing one of them
- Subject: Closing all windows when closing one of them
- From: James Mastro <email@hidden>
- Date: Fri, 17 Jun 2005 17:47:34 -0400
Hello everyone. I'm just getting back into Cocoa after a long time away
from it. But I've run into a problem. My app is fairly simple. I open
one main window, and it can also open a bunch of windows of another
type in response to user actions. If the main window gets closed, I
want all the windows to close. But I don't want the app to quit.
So what I was doing was just responding to windowWillClose: in my main
window controller, and calling this function from it:
- (void) closeAllWindows
{
NSArray* windows = [NSApp windows];
int x;
for (x = 0; x < [windows count]; x++)
{
NSWindow* win = [windows objectAtIndex:x];
[win close];
}
}
That doesn't work because [win close] will try to close the window
which called it, that is in the process of closing but has not been
kicked out of the window list yet. Which will call closeAllWindows:
again, etc. So it goes around in a circle like that until my app
crashes.
My hack around this was to respond to windowShouldClose, and return NO
from it always. But if the user did in fact hit "OK" to close it,
before returning NO I call closeAllWindows. Returning NO makes sure I
only get one [win close] called, the one being called in
closeAllWindows. There can only be one of the main window created, so I
could probably hack in a boolean to know if I'm in the process of
closing. Or maybe hide it to get it out of the window list. But they
are all terrible hacks and I'd like to know how I can do this without
any hackage?
-jim
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden