2
votes

I'm trying to present a new view controller that comes in via the presenting view controller being dismissed and having the presented view controller 'already' be behind the presenting one, much in the same way a modal view controller is presented/dismissed.

Is there a way to achieve this by just presenting the view controller, or do I somehow have to present the view controller before hand and then hide it underneath and then dismiss the presenting view controller?

1
How is the current view controller presented? Modally? In a nav controller? As a child of something else?Wain
does my answer help? do you have any more questions? :) @micnguyennburk

1 Answers

3
votes

You can do this indeed by "hiding" your second view controller underneath the first view controller that you want to display. UINavigationController gives you everything you need for this for free.

Use the following (pseudo-)code from the view controller where you are showing the modal view:

FirstVC *first = [[FirstVC alloc] init]; // this VC is shown first
SecondVC *second = [[FirstVC alloc] init]; // this VC that hides beneath the other

UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:second];
[nav pushViewController:first animated:NO];

[self presentViewController:nav animated:YES completion:nil];

Then, whenever you want to dismiss the first view controller, you can call:

[self.navigationController popViewControllerAnimated:YES];

Note that you still will have to dismiss the modal view then.