2017-03-06 52 views
0

我有一個加載指標,用UIAlertController實現。當我發送認證請求到服務器 - 我啓動加載指標。當請求成功時,我必須轉到另一個ViewController並隱藏加載指示器。在我執行segue之前,我需要等到AlertController解除指示完成。所以,我有這樣一個邏輯:從alertcontroller segue從不採取行動

private var loadingIndicator: UIAlertController? 

func navigateToMonitoring() { 
     DispatchQueue.global(qos: .background).async { 
      if let indicator = self.loadingIndicator { 
       while !indicator.isBeingDismissed { continue } 
       DispatchQueue.main.async { 
        self.performSegue(withIdentifier: "Monitoring", sender: self) 
       } 
      } 
     } 
    } 

但是,當這種方法執行我有一個消息 - 警告:試圖提出有關誰的觀點是不是在窗口層次! - 並且segue不執行。

我該如何解決這個問題?

(SWIFT 3,Xcode中8)

+0

**不要等待!**這種重複循環是可怕的。使用完成處理程序。 – vadian

回答

0

你也許可以創建警報,並保存其引用,則顯示警告並調用API,並且在API的完成塊,你可以關閉它並執行SEGUE ,希望這對你有意義。