0
votes

I'm making a Cocoa application with two windows. I want to hide both of these windows, call some screen capture functionality and then restore the windows. I use

[mainWindow orderOut:self];

to hide the window, but when I do this, the whole application closes. In my AppDelegate I have the function:

- (BOOL)applicationShouldTerminateAfterLastWindowClosed:(NSApplication*)sender 
{
    return YES;
}

Am I hiding the window incorrectly? Why does the AppDelegate think the window has been closed when using orderOut?

My app works perfectly without using the method above in AppDelegate, I added it in as a final step to terminate the application when I actually close all of the windows. Can anyone suggest how to make my windows temporarily invisible without closing the application?

2

2 Answers

1
votes

I forget... can you setVisible: of a window? If so that would solve it.

The only other thing would be to set a BOOL when you programatically close the windows... iClosed Windows = YES. Then set it to NO when you restore the windows... then check that bool in the delegate method and return YES or NO accordingly.

0
votes

Remove method applicationShouldTerminateAfterLastWindowClosed. Application will remain open. This is the normal behavior on OS X. You can close all the windows of Chrome or Safari and they will remain open. OS X will close them if there is a need, like on iOS.