Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to re-show main window after closed in Cocoa?

Tags:

macos

cocoa

I want to re-show the main window after closed when click my app icon on dock. Anyone know how to do it ? Thanks in advance.

like image 403
Irwan Avatar asked Feb 09 '10 02:02

Irwan


1 Answers

In @implementation:

Make step 1

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

where _window is your window that will reopen in future

Make step 2

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

where _window is your closed window

like image 61
Daniel Valeriev Avatar answered Oct 20 '22 21:10

Daniel Valeriev