如何在另一个模态视图的前面显示NSSAVEPANEL模式窗口



我正在使用可可(Cocoa)开发基于MacOS文档的应用程序。我想做一个像Xcode的启动一样的行为,即:在窗口中,开始模态视图,其控制器的控制器被presentViewControllerAsSheet:称为viewController,然后单击"下一个"按钮,通过运行[self saveDocument:self]。>

我的代码是:

self.viewController = [[ViewController alloc] initWithNibName:@"ViewController" bundle:nil]
[self.contentViewController presentViewControllerAsSheet:viewController;
//...some set ups about the NSButton on the view.
//And in the method to handle the Next Button being clicked:
[self saveDocument:self];

运行应用程序后,当我单击"下一个"按钮时,什么也不会发生。

我自己只是处理这个问题。我从辅助控制器回电给我的主文档类,并保存数据,试图调用save()没有显示模式对话框。原来,我不得不明确拨回主线程以确保显示UI:

newServerWindowController?.saveNewDocument = { remote in
    DispatchQueue.main.async {
        guard let newDoc = self.document else { return }
        newDoc.remote = remote
        newDoc.save(self)
        self.windowController?.update()
    }
}

希望这会有所帮助!

最新更新