os x应用点击关闭按钮退出程序的方法

先前只知道加入一个代理,就可以实现:

- (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];
}

相关博文

    分享到:

About rainbird

IOS攻城狮
This entry was posted in Mac开发 and tagged , , , , , , . Bookmark the permalink.

One Response to os x应用点击关闭按钮退出程序的方法

  1. jackoutlook says:

    老大,在那里加这些命令求详细过程

发表评论