首先AppDelegate实现window的代理;
- @interface AppDelegate : NSObject <NSApplicationDelegate,NSWindowDelegate>
最后实现下面两端代码,如果实现了第一段代码,第二段代码就会失效:
1、完全退出程序
- - (BOOL)windowShouldClose:(id)sender //close box quits the app
- {
- [NSApp terminate:self];
- return YES;
- }
2、隐藏后点击dock图标重新显示
- - (BOOL)applicationShouldHandleReopen:(NSApplication *)theApplication hasVisibleWindows:(BOOL)flag
- {
- if (!flag){
- [self.window makeKeyAndOrderFront:self];
- return YES;
- }
- return NO;
- }