Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

While an existing transition or presentation is occurring; the navigation stack will not be updated

Tags:

ios

swift

I have encountered this warning:

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

While trying to call navigationController?.popViewControllerAnimated(false) from UIAlertController completion block.

like image 672
Siddu Halake Avatar asked May 17 '16 07:05

Siddu Halake


4 Answers

This warning indicates that you are trying use UINavigationController wrongly:

pushViewController:animated: called on while an existing transition or presentation is occurring; the navigation stack will not be updated

You mentioned in the comments that you are trying to pop the ViewController using

navigationController?.popViewControllerAnimated(false)

inside completion block of UIAlertController. Therefore, you are trying to unwind from the wrong view, UIAlertController is not part of the UINavigationController stack.

Try and close the UIAlertController first, then pop the current ViewController. In other words, remove the pop from the completion block and put it inside the OK block. or use unwind segue before the alert.

Another possibility, is that you have an unused or identical duplicate in storyboard. Hence, if the unwinding operation is triggered by storyboard button, select this button and check the connectivity inspector and removed unwanted connections.

For example: the red x marked was unnecessary in my case. Example

like image 159
Idan Avatar answered Nov 20 '22 14:11

Idan


I solved this using DispatchQueue.main.asyncAfter call popviewcontroller after the UIAlertController's Transition complete

1) Show Alert

2) Call pop viewcontroller after delay

DispatchQueue.main.asyncAfter(deadline: .now() + 0.5) {
    self.navigationController?.popToRootViewController(animated: true)
}

This is not best way, but it works!

like image 42
Meghs Dhameliya Avatar answered Nov 20 '22 14:11

Meghs Dhameliya


Add the code of navigate controller on the ok action button handler. When Tap on ok button navigate the view controller

let okActionBtn = UIAlertAction(title: "Ok", style: .default, handler: {
      self.navigationController?.popViewController(animated: true)
})
let cancelActionBtn = UIAlertAction(title: "Cancel", style: .cancel, handler: nil)
let alert = UIAlertController(title: "Title", message: "Message", preferredStyle: .alert)
alert.addAction(okActionBtn)
alert.addAction(cancelActionBtn)
self.present(alert, animated: true)

   

like image 3
Sourabh Kumbhar Avatar answered Nov 20 '22 16:11

Sourabh Kumbhar


i am using dispatch_async and its working. i tried to navigate back but didn't worked because navigation stack will not be updated.

let destVC = self.storyboard?.instantiateViewControllerWithIdentifier("HomeViewController") as! HomeViewController
    self.presentViewController(destVC, animated: true, completion: {() -> Void in
        dispatch_async(dispatch_get_main_queue(), {() -> Void in
            self.navigationController?.popViewControllerAnimated(true)!
        })
    })
like image 2
Mr.Javed Multani Avatar answered Nov 20 '22 16:11

Mr.Javed Multani