Closing Mac application (clicking red cross on top) and reopening by clicking dock icon

≯℡__Kan透↙ 提交于 2019-11-30 12:33:25

If you are still concerned how to reopen the window that you have closed, use this method:

- (BOOL)applicationShouldHandleReopen:(NSApplication *)theApplication hasVisibleWindows:(BOOL)flag {

[window makeKeyAndOrderFront:self];

return YES;
}

You can use this to handle clicks on the applications icon in the dock.

For further information check out the NSApplicationDelegate Protocol Reference.

Here is the documentation:

http://developer.apple.com/library/mac/#documentation/cocoa/reference/NSApplicationDelegate_Protocol/Reference/Reference.html

Hope this helps!

Implement the method

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

in your app delegate

Your app will hang around after the window is closed and then if you implement

- (void)applicationDidBecomeActive:(NSNotification *)aNotification
{
//dock icon has just been clicked , or cmd-tabbed into
}

in the app delegate

You can do things when the icon is clicked such as open a new or old window if you need to

See http://developer.apple.com/library/mac/#documentation/cocoa/reference/NSApplicationDelegate_Protocol/Reference/Reference.html for other relevant application events

I think that the answers above aren't fully correct, to achieve this you should override applicationShouldHandleReopen(_:hasVisibleWindows:) https://developer.apple.com/reference/appkit/nsapplicationdelegate/1428638-applicationshouldhandlereopen

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!