簡體   English   中英

如何在SWIFT中解除沒有動作的UIAlertController?

[英]How to dismiss an UIAlertController with no actions in SWIFT?

我的圖像下載時顯示UIAlertController。 下載完成后,我想推送一個視圖控制器。 我在控制台中有錯誤,因為我沒有關閉警報控制器:

pushViewController:animated: called on <UINavigationController 0x7fb190c6ee00> while an existing transition or presentation is occurring; the navigation stack will not be updated.

在我的主視圖控制器中,當下載完成時,我推送另一個視圖:

override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {

    //....

    var alert = UIAlertController(title: "Alert", message: text, preferredStyle: UIAlertControllerStyle.Alert)
    self.presentViewController(alert, animated: true, completion: nil)


    dispatch_async(dispatch_get_main_queue(), {
        if let cellToUpdate = tableView.cellForRowAtIndexPath(indexPath) {
               self.performSegueWithIdentifier("postview", sender: self)

        }
   })
}

我嘗試過dismissViewControllerAnimated,但我有完全相同的錯誤:

dispatch_async(dispatch_get_main_queue(), {
            if let cellToUpdate = tableView.cellForRowAtIndexPath(indexPath) {
                   alert.dismissViewControllerAnimated(true, completion: nil)
                   self.performSegueWithIdentifier("postview", sender: self)

            }
       })

在解除上一個視圖控制器之前,不應調用performSegueWithIdentifier 要正確計時,請從完成處理程序執行此操作:

dispatch_async(dispatch_get_main_queue(), {
    if let cellToUpdate = tableView.cellForRowAtIndexPath(indexPath) {
       alert.dismissViewControllerAnimated(true, completion: {
           self.performSegueWithIdentifier("postview", sender: self)
       })
    }
})

現在執行segue的調用在解雇結束之前不會啟動,從而防止您看到的錯誤。

暫無
暫無

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

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