簡體   English   中英

像NSAlert這樣的MacOS Modal對話框

[英]MacOS Modal Dialog like NSAlert

我正在編寫一個應用程序,它將逐步處理大量數據,當它遇到特定條件時,我想顯示一個自定義對話框,允許用戶編輯數據的某些信息。 我已經嘗試過使用模態定序。

但是,當我運行代碼時,它將立即打開所有對話框。 即使打開了“模態”對話框,它也會繼續逐步瀏覽數據。

例:

for x in 1...10 {
    print("X is: \(x)")
    self.presentAsModalWindow(sheetViewController)
}

這將顯示10個窗口...它不是真正的模態窗口。

我希望它像NSAlert一樣工作,其中的執行將停止,直到關閉對話框為止。 NSAlert無法使用,因為我需要模式窗口上的教科書和其他控件。

有人有任何想法如何實現這一目標嗎?

提前致謝!

代替presentAsModalWindow,使用

NSApp.runModal(for: NSPanel(contentViewController: sheetViewController))

在SheetViewController中,您必須根據邏輯關閉modalWindow。

@IBAction func buttonClicked(_ sender: NSButton) {

    if NSApp.modalWindow == self.view.window && NSApp.modalWindow!.isVisible {

        NSApp.stopModal() // Use .stopModal(withCode: .OK) if response has to be sent
        self.view.window?.close()
    }
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM