How to re-show the main window after closing in Cocoa?

I want to show the main window again after closing by clicking the application icon on the dock. Does anyone know how to do this? Thank you in advance.

+5
source share
2 answers

Bring applicationShouldHandleReopen:hasVisibleWindows:in your application delegate. In your implementation, order the window back. (Make sure you don’t let it go, and it will not be released when it closes.)

See the documentation .

+7
source

In @implementation:

Take step 1

- (void)applicationDidFinishLaunching:(NSNotification *)aNotification{
       [_window setReleasedWhenClosed:NO]; 
  }

where _windowis your window that will open in the future

Take step 2

- (BOOL)applicationShouldHandleReopen:(NSApplication *)sender hasVisibleWindows:(BOOL)flag{
    [_window setIsVisible:YES];
    return YES;
}

where _windowis your closed window

+14

All Articles