I want to push from VC 1 to VC 3 but when VC 3 pops I want to be on VC 2. Is there a way I can secretly put VC 2 infront of VC 3 before poping VC 3?
Is it possible to insert a UIViewController between two view controllers of an UINavigationController?
Could you explain your intent ? What do you want to achieve ? What do you want user to see and not see ?
What fo you mean "you want to "secretly (?!?) put VC2 in front of VC3"
If so, in prepare, you could just load VC2 but not present it.
See:
https://stackoverflow.com/questions/25745854/how-to-initiate-a-viewcontroller-without-presenting-it
What fo you mean "you want to "secretly (?!?) put VC2 in front of VC3"
do you just want to load VC2 ? But no show ?
If so, what does "in front VC3" mean ?
If so, in prepare, you could just load VC2 but not present it.
See:
https://stackoverflow.com/questions/25745854/how-to-initiate-a-viewcontroller-without-presenting-it
Thank you for your reply, this is the detailed case of my drawing app:
I have three view controllers:
Then after the IntroVC is finished I push to the MenuVC with a custom animation:
When the user decides to start drawing the MenuVC will push to the CanvasVC, like this:
After the user finishes his drawing he can pop to the MenuVC again, like this:
This is the usual flow, but on the first start, instead of presenting the IntroVC a OnboardingVC is presented.
The Onboarding has a little introduction and after the introduction it should push the user into the CanvasVC directly without pushing the MenuVC.
When the user is done in the CanvasVC I want to call:
and be in the MenuVC again, not in the OnboardingVC. There for I asked, if I can put the MenuVC inbetween the OnboardingVC and the CanvasVC, without pushing it on the navigation stack.
I hope my explanation is understandable :)
I have three view controllers:
IntroVC
MenuVC
CanvasVC
Code Block let navigationController = UINavigationController(rootViewController: IntroVC()) self.window?.rootViewController = navigationController
Then after the IntroVC is finished I push to the MenuVC with a custom animation:
Code Block self.navigationController?.pushViewControllerWithWaveTransition(to: MenuVC())
When the user decides to start drawing the MenuVC will push to the CanvasVC, like this:
Code Block self.navigationController?.pushViewController(pageVCC, animated: true)
After the user finishes his drawing he can pop to the MenuVC again, like this:
Code Block self.navigationController?.popViewController(animated: true)
This is the usual flow, but on the first start, instead of presenting the IntroVC a OnboardingVC is presented.
The Onboarding has a little introduction and after the introduction it should push the user into the CanvasVC directly without pushing the MenuVC.
When the user is done in the CanvasVC I want to call:
Code Block self.navigationController?.popViewController(animated: true)
and be in the MenuVC again, not in the OnboardingVC. There for I asked, if I can put the MenuVC inbetween the OnboardingVC and the CanvasVC, without pushing it on the navigation stack.
I hope my explanation is understandable :)
I just found the answer:
after pushing the CanvasVC.
Code Block self.navigationController?.viewControllers.insert(MenuVC, at: 1)
after pushing the CanvasVC.
Why don't you just add the View over OnboardingVC, with addSubview ?if I can put the MenuVC inbetween the OnboardingVC and the CanvasVC, without pushing it on the navigation stack.
Instead of pushing the CanvasVC onto the stack from the OnboardingVC, use the navigation controller's setViewControllers:animated: method to pass an array with the MenuVC and CanvasVC. That will replace the OnboardingVC with the MenuVC and when you pop back from CanvasVC you will return to the MenuVC (and it will be the top-most view controller in the navigation stack).This is the usual flow, but on the first start, instead of presenting the IntroVC a OnboardingVC is presented.
The Onboarding has a little introduction and after the introduction it should push the user into the CanvasVC directly without pushing the MenuVC.
It's not clear if the user can ever navigate back from the MenuVC to your IntroVC. Probably not. So you could do the same thing to remove IntroVC from the stack and release its memory. Although it sounds like you might be using some sort of custom presentation (pushViewControllerWithWaveTransition) so that might not work.