0

So I have 3 view controllers (and a nav view controller). Starting at VC1 I push to VC2 then when the scene for VC2 is done I pop VC2 then push to VC3. Only problem with that is that the user can see the stack push/popping. Is there anyway I can push VC3 then pop VC2 without it being noted? I know it's a stack so you can't necessarily pick elements as you can arrays, but maybe there is a way I can pop VC2 from VC3?

I saw a few stackoverflow resources but all in old syntax from 2011-2014 and are very outdated. Anyone have any ideas?

rmaddy
  • 314,917
  • 42
  • 532
  • 579
insta catering
  • 151
  • 2
  • 12
  • Leave VC2 in place and just push VC3. But when you want to leave VC3, pop to VC1. You get the same desired effect. – rmaddy Feb 09 '17 at 23:16
  • BTW - solutions from 2011-2014 are still valid. Just convert to Swift 3 as needed. – rmaddy Feb 09 '17 at 23:17
  • I would do that. But I need to dismiss the scene presented in VC2 as well. When I posted this 10 minutes ago it seemed to work but now that I have the volume up, it doesn't. Should I just do: self.viewcontroller?.presentScene(nil) then push to VC3? – insta catering Feb 09 '17 at 23:17

1 Answers1

1

Yes you can. You can use the setViewControllers:animated: method. Like this:

navigationController?.setViewControllers([vc1, vc3], animated: true)

This will animate a push while removing the vc2 from the stack and replacing it with vc3. More info about the method here.

Update:

If you don't have a reference to vc1 in v2 (and you probably don't) you can do this:

navigationController?.setViewControllers(navigationController!.viewControllers.first!, vc3], animated: true)

Oh, and if you wish to push vc3 without any animation then, obviously, just call the method with animated: false.

Mihai Fratu
  • 7,579
  • 2
  • 37
  • 63