【MacOS】Mac应用点击关闭按钮就退出程序的方法(等同Command + Q)
先前只知道加入一个代理,就可以实现:
- (BOOL)applicationShouldTerminateAfterLastWindowClosed:(NSApplication *)sender{
return YES;
}
今天在cocoachina上看到了更科幻的方法,记录一下:
NSButton *closeButton = [self window] standardWindowButton:NSWindowCloseButton];
[closeButton setTarget:self];
[closeButton setAction:@selector(closeApplication)];
- (void) closeApplication {
[NSApplication sharedApplication] terminate:nil];
}
http://www.cocoachina.com/bbs/read.php?tid=113181
- (BOOL)applicationShouldTerminateAfterLastWindowClosed:(NSApplication *)sender{
return YES;
}
今天在cocoachina上看到了更科幻的方法,记录一下:
NSButton *closeButton = [self window] standardWindowButton:NSWindowCloseButton];
[closeButton setTarget:self];
[closeButton setAction:@selector(closeApplication)];
- (void) closeApplication {
[NSApplication sharedApplication] terminate:nil];
}
http://www.cocoachina.com/bbs/read.php?tid=113181
> 我来回应