1

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

理由がわかりません。アラートをシートとして表示する方法を知りたいです。私を助けてください!!

4

1 に答える 1

0

それは私のために働いた。についてはあまり知りません。

パーツのせいかもbeginSheetModalForWindow:

あなたの質問では、それはbeginSheetModalForWindow:mainWindowController.window

以下に示すように、に変更しましたmainWindowController.windowが、機能しました。self.view.window

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

多分それは私が考えるのに役立つかもしれません。

于 2018-02-28T07:50:08.077 に答える