1

I have four viewController let A,B,C,D. And my flow is from A to D.I want to remove B view controller when I have reached to D. I am using present viewController to present next view.

  • so you would like to move back from C to A directly? – PPL May 09 '18 at 12:47
  • yes, i want to remove back flow C to B – user9294044 May 09 '18 at 12:50
  • @KristopherJohnson I guess its not navigation stack he is presenting instead of pushing. – TheTiger May 09 '18 at 12:51
  • 1
    @user9294044 By presenting its not possible but if you use `navigationController` then it has `viewControllers` property which is an array and you can `remove/replace/add` any `controller` to it. Even you can use custom `presenting/dismissing` animation while `pushing` and `popping`. – TheTiger May 09 '18 at 12:54
  • 1
    @user9294044 what you actually want? please elaborate more – PPL May 09 '18 at 13:02

1 Answers1

-1

From your eg., In D Screen you need to check self.navigationController?.viewControllers and remove desired ViewController.

    var newArray = [UIViewController]()

    if let viewControllers = self.navigationController?.viewControllers {
        for vc in viewControllers {

            if !(vc is <#Desired ViewController#>) {
                newArray.append(vc)
            }
        }
       self.navigationController?.viewControllers = newArray
    }
Mahendra
  • 8,448
  • 3
  • 33
  • 56