首先AppDelegate实现window的代理;
[plain]view plain copy print ? @interfaceAppDelegate:NSObject<NSApplicationDelegate,NSWindowDelegate>
接着将window的delegate链接到AppDelegate;
最后实现下面两端代码,如果实现了第一段代码,第二段代码就会失效:
1、完全退出程序
[plain]view plain copy print ? -(BOOL)windowShouldClose:(id)sender//closeboxquitstheapp { [NSAppterminate:self]; returnYES; }
2、隐藏后点击dock图标重新显示[plain]view plain copy print ? -(BOOL)applicationShouldHandleReopen:(NSApplication*)theApplicationhasVisibleWindows:(BOOL)flag { if(!flag){ [self.windowmakeKeyAndOrderFront:self]; returnYES; } returnNO; }