2017-04-04 28 views
0

我是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()沒有執行,但仍然不是運氣。

任何幫助表示讚賞。謝謝

+0

所以你有一些錯誤,或者你的意思是「沒有運氣」 –

+0

對不起,主窗口中的第二個URLRequest不會出現在後臺線程中 – Tim

+0

我們需要爲代碼,你沒有顯示任何東西,這段代碼沒有做任何嚴重的事情 –

回答

0

不要在模態中運行你的主視圖,模態應該用於對話框。所以你可以在模態下運行登錄視圖(並通過在應用程序上調用stopModal來完成)。在這種情況下,你可以使用像loadLoginView這樣的水印,它與你當前的loadMainView(但沒有這個self.view.window?.close()調用)具有類似的實現。主視圖將在應用程序啓動時從nib加載,但你必須張貼更多的代碼(你的應用程序初始化看起來像?)得到的幫助。