ios - Unwind then segue without showing intermediate view controller


Keywords:ios 


Question: 

I have three UIViewControllers where A -> B -> C, and A -> D.

When the user is done in C I want to unwind back to A and then segue to D, but I cannot get this to work without briefly showing A before the segue to D happens. I have tried disabling the animates property for the segue but A still flashes into view for less than a second.

Any idea as to how I can fix this?


1 Answer: 

Try this Code in swift 3 :-

let oldVCs = self.navigationController?.viewControllers
var newVCs = [UIViewController]()

// Add your root VC in new array of VCs
newVCs.append(oldVCs![0])
// Add your new VC just after your root VC
newVCs.append("Your New VC")

self.navigationController?.setViewControllers(newVCs, animated: true)