先前只知道加入一个代理,就可以实现:
- (BOOL)applicationShouldTerminateAfterLastWindowClosed:(NSApplication *)sender{
return YES;
}
return YES;
}
今天在cocoachina上看到了更科幻的方法,记录一下:
NSButton *closeButton = [[self window] standardWindowButton:NSWindowCloseButton];
[closeButton setTarget:self];
[closeButton setAction:@selector(closeApplication)];
- (void) closeApplication {
[[NSApplication sharedApplication] terminate:nil];
}
[closeButton setTarget:self];
[closeButton setAction:@selector(closeApplication)];
- (void) closeApplication {
[[NSApplication sharedApplication] terminate:nil];
}