How to reject UIAlertController without any action in SWIFT?

I show UIAlertController when loading my image. When the download is complete, I want to click the view controller. I have an error in the console because I am not rejecting the warning controller:

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

In my main view controller, when the download is complete, I click another view:

 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) } }) } 

I tried wit to remove ViewControllerAnimated, but I have exactly the same error:

 dispatch_async(dispatch_get_main_queue(), { if let cellToUpdate = tableView.cellForRowAtIndexPath(indexPath) { alert.dismissViewControllerAnimated(true, completion: nil) self.performSegueWithIdentifier("postview", sender: self) } }) 
+5
source share
1 answer

You should not call performSegueWithIdentifier before the previous view controller was fired. To do this correctly, do this using the completion handler:

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

Now the call to execute segue will not start until the dismissal ends, preventing the error that you see.

+9
source

Source: https://habr.com/ru/post/1208501/


All Articles