簡體   English   中英

進行異步調用后運行Modal

[英]Run Modal after async call made

我是Swift Mac App開發的新手,在登錄URLRequest之后,我需要從登錄窗口轉到顯示主窗口,然后在新的主窗口中創建另一個URLRequest。 如果我只是從一個窗口進入而沒有進行登錄URLRequest,那么它將正常工作。

func loadMainView() {

    self.view.window?.close()

    let storyboard = NSStoryboard(name: "Main", bundle: nil)
    let mainWindowController = storyboard.instantiateController(withIdentifier: "MainViewController") as! NSWindowController

    if let mainWindow = mainWindowController.window {

        let application1 = NSApplication.shared()
        application1.runModal(for: mainWindow)
    }
}

func tryLogin(_ username: String, password: String ) {

    Staff.login(username: self.username.stringValue, password: self.password.stringValue) { (completed, result, staff) in
         // DispatchQueue.main.async {
        if completed {

            if result == .Success && staff != nil {

                DispatchQueue.main.async(execute: {
                   self.loadMainView()
                })
            } else {

                self.dialogOKCancel(message: "Error", text: "Your credentials are incorrect")
            }

        } else {
            print("error")
        }
    }
}

HTTPSConnection.httpGetRequestURL(token: token, url: digialOceanURL, mainKey: mainKeyVal) { ( complete, results) in

        DispatchQueue.main.async {
            if complete {

            }
        }

    }

我試過在沒有執行的情況下調用self.loadMainView(),但還是不走運。

任何幫助表示贊賞。 謝謝

不要以模態運行主視圖,應將模態用於對話框。 因此,您可以以模式運行登錄視圖(並通過在應用程序上調用stopModal來完成登錄視圖)。 在這種情況下,您可以使用諸如loadLoginView類的loadLoginView ,其實現與當前的loadMainView相似(但是沒有此self.view.window?.close()調用。主視圖將在應用程序啟動時從nib加載。)發布更多代碼(您的應用初始化如何?)以獲取幫助。

暫無
暫無

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

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