0

I have 2 UIViewControllers, UIViewControllerA and UIViewControllerB in a UINavigationController stacked in this manner -> [UIViewControllerA, UIViewControllerB]. Now instead of popping UIViewControllerB to reach UIViewControllerA, I want to swap the 2 objects in navigation stack.

So I do this :

self.navigationController?.setViewControllers([UIViewControllerB, UIViewControllerA], animated: true)

After this when I query my navigation stack, there is only 1 view controller i.e. [UIViewControllerA]

Question 1: Why I cannot find UIViewControllerB as root view controller?

Question 2: I want to again swap the 2 view controllers to reach UIViewControllerB. How to achieve this, if possible?

crypt
  • 449
  • 5
  • 15
  • First Please, answer to the question. Why you need do this? Can you describe you flow? I guess, we can find solution using the next possible solutions: unwind segues, push a new one controller. All data we can pass to another controller instance if it need. – LLIAJLbHOu Aug 04 '18 at 09:54
  • If we use unwind segue or pop the view controller, the temporary data created in the UIViewControllerB will be lost or will have to be saved somewhere. But due to existing complexities, I am trying to avoid that. The purpose of swapping is so that user can just peek into the UIViewControllerA and return back to UIViewControllerB. So I am trying to save the effort of persisting data of UIViewControllerB when the user moves back to the previous viewcontroller i.e. UIViewControllerA. I hope this gives a clear picture of the use case. – crypt Aug 05 '18 at 08:02

0 Answers0