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

前端 未结 2 1440
情深已故
情深已故 2021-02-04 18:09

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.

2条回答
  •  太阳男子
    2021-02-04 18:45

    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

提交回复
热议问题