0
votes

I am trying to pop a view controller VC1 from one navigation controller NC1 to another view controller VC2 in another navigation controller NC2.

I am using the VIPER architecture thus routing between different view controllers in different navigational hierarchies requires that I must switch to the root of the navigation controller I want to present.

So the issue here is that, after navigating to the view controller VC2 of the second navigation controller NC2, I want to go back to the first view controller VC1 in the first navigation controller NC1.

I have tried the following:

 self.navigationController?.popViewController(animated: true)

 navigationController?.dismiss(animated: true, completion: nil)

 view.window?.rootViewController?.dismiss(animated: true, completion: nil)

 self.navigationController?.popToRootViewController(animated: true)

but none of them worked for me. Any ideas?

1
I'm not sure if I can fully understand your question, if you want to change the window's root view controller you can just dismiss the current VC1 and set the NC2 as rootView controller of the window?Mina
You can manage all the navigation flow of your application by creating a new singleton class like AppNavigationFlow. And that singleton class you can store your both navigationController objects.bestiosdeveloper
For your solution can you place some more code or structure of all viewControllers till the screen on which you are trying to dismiss.bestiosdeveloper
Your question is not quite clear... Do you have a presented NC1 (that is, presented modally over a current view controller) that is currently showing VC1 and you want to tap a button to navigate to NC2 showing VC2?DonMag
@DonMag, I just edited the question, I think that should make it clearer, I want to move back to the first view controller VC1 in the first navigation controller NC1, but because I did not present the second VC2 modally, I cannot just dismiss the view controller VC2 in the second navigation controller NC2Ewurafua Plange

1 Answers

0
votes

Please Try this codes :

let viewControllers = self.navigationController?.viewControllers

for vc in viewControllers! {

   if vc is VC1 {
      self.navigationController?.popToViewController(vc as! VC1, animated: true)
   }
}