Skip to content

Instantly share code, notes, and snippets.

@summic
Created November 21, 2012 03:21
Show Gist options
  • Save summic/4122809 to your computer and use it in GitHub Desktop.
Save summic/4122809 to your computer and use it in GitHub Desktop.
小技巧:如何恢复显示关闭的窗口
在Mac OS中,点击窗口左上方的x,窗口将会关闭。如果你希望通过点击dock上的图标将窗口重新打开,你可以用如下方法做。
实现方法如下:
在delegate里设置一个outlet,比如myWindow:
IBOutlet NSWindow *myWindow;
在Interface Builder中,将主窗口的"Release When Closed"选项取消掉。再将delegate里的myWindow和你的主窗口连接起来,然后在delegate里实现如下方法:
- (BOOL)applicationShouldHandleReopen:(NSApplication *)theApplication hasVisibleWindows:(BOOL)flag
{
if (flag) {
return NO;
}
else
{
[myWindow makeKeyAndOrderFront:self];
return YES;
}
}
这样窗口即使被关闭,也可以点击dock上的图标重新恢复显示。
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment