2

I am using a UINavigationController.

Lets say I have these stacks

VC1 -> VC2 -> VC3 
VC1 -> VC3
VC1 -> VC2 -> VC4 -> VC3

In all cases, how can I dismiss all VC's below VC3 when it is the current view controller.

VC3 is connected to a TabBarController if this make a difference.

5
  • you want VC3 TabBarController as root View and remove the whole UINavigationController with VC1 and VC2 ? Commented Aug 1, 2018 at 12:48
  • pretty much yh @Amit Commented Aug 1, 2018 at 12:49
  • you can directly change the root View controller by adding self.view.window?.rootViewController = TabBarController in VC2. Commented Aug 1, 2018 at 12:51
  • Since you have navigation controller, what do you mean by "dismiss" the view controllers? Why do you need to do this? Commented Aug 1, 2018 at 12:52
  • I dont want the user to swipe back from VC3, but I can't disable the gesture recognizer on individual VC's. I will try your suggestion thank you. Commented Aug 1, 2018 at 12:53

3 Answers 3

2

From VC2, use setViewControllers method to push VC3 and to remove the rest,

self.navigationController?.setViewControllers([VC3], animated: true)
Sign up to request clarification or add additional context in comments.

Comments

0

You can remove a view controller from the navigation controller stack like that: self.navigationController?.viewControllers.remove(at: index)

2 Comments

sorry i didnt specify in question but the number of VC's below VC3 is ambiguos. There can be 1 view controller or 3 view controllers
In that case all you need to do is just set the VC3 as the only VC, like the answer below. Basically you should set the array by setting setViewControllers with the top most VC in your case the VC3.
0

In your scenario it's better to change the application's root view from UINavigationController to UITabBarcontroller.

You can achieve that by doing in any VC:

self.view.window?.rootViewController = TabBarController

To know more about it you can check this link:

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.