我有以下代码,希望在AppDelegate.m中显示警告。
- (NSApplicationTerminateReply)applicationShouldTerminate:(NSApplication *)sender {
if ([self.socket.inputStream streamStatus] == 2) {
NSStoryboard *storyBoard = [NSStoryboard storyboardWithName:@"Main" bundle:nil];
NSWindowController *mainWindowController = [storyBoard instantiateControllerWithIdentifier:@"MainWindow"];
NSAlert *alert = [[NSAlert alloc] init];
[alert addButtonWithTitle:@"OK"];
[alert setMessageText:NSLocalizedString(@"Warning", @"Warning")];
[alert setInformativeText:NSLocalizedString(@"Disconnect before quit this app!!", @"Disconnet before quit")];
[alert beginSheetModalForWindow:mainWindowController.window completionHandler:^(NSModalResponse returnCode) {
}];
return NO;
} else {
return YES;
}
}
但不幸的是,结果警报未显示为表格。像截图一样。
我不明白为什么。并且想知道如何以表格形式显示警报。请帮我!!
它对我有用。我不太了解。
可能是因为部分beginSheetModalForWindow:
在你的问题,似乎beginSheetModalForWindow:mainWindowController.window
我将它从mainWindowController.window
更改为self.view.window
并且它有效,如下所示:
[alert beginSheetModalForWindow:self.view.window completionHandler:^(NSModalResponse returnCode)
{
....
}];
可能它会帮助我思考。