Cocoa NSAlert不会以表格形式显示警报

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Cocoa NSAlert不会以表格形式显示警报相关的知识,希望对你有一定的参考价值。

我有以下代码,希望在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;
    }
}

但不幸的是,结果警报未显示为表格。像截图一样。

doesNotShowAlertAsSheet

我不明白为什么。并且想知道如何以表格形式显示警报。请帮我!!

答案

它对我有用。我不太了解。

可能是因为部分beginSheetModalForWindow:

在你的问题,似乎beginSheetModalForWindow:mainWindowController.window

我将它从mainWindowController.window更改为self.view.window并且它有效,如下所示:

[alert beginSheetModalForWindow:self.view.window completionHandler:^(NSModalResponse returnCode)
{
    ....
}];

可能它会帮助我思考。

以上是关于Cocoa NSAlert不会以表格形式显示警报的主要内容,如果未能解决你的问题,请参考以下文章