根据 Apple 开发人员技术支持,这是一个已知问题。我终于把app的退出菜单项的自动连线剪掉了,全部自己处理。我需要使文档的服务器功能信息从外部可用(在本例中为 的状态optionButton
)并将此功能添加到AppDelegate
:
- (IBAction)terminateGracefully:(id)sender {
BOOL optionOn = FALSE;
for (Document *doc in NSApp.orderedDocuments) {
if (doc.optionButton.state == NSControlStateValueOn) {
optionOn = TRUE;
}
}
if (optionOn) {
NSAlert *alert = [[NSAlert alloc] init];
[alert setMessageText:@"Checkbox in some window is on"];
[alert setInformativeText:@"Something is going on. If you close the app now, it will stop. Close anyway?\n"];
[alert setAlertStyle:NSAlertStyleCritical];
[alert addButtonWithTitle:@"Don't close"];
[alert addButtonWithTitle:@"Close anyway"];
NSModalResponse resp = [alert runModal];
if (resp == NSAlertSecondButtonReturn) {
// We really want to close
[NSApp terminate:sender];
}
} else {
[NSApp terminate:sender];
}
}
然后我将应用程序的退出菜单项绑定到terminateGracefully:
