How to present a second ViewController & dismiss the first

Tim Windsor Brown picture Tim Windsor Brown · Mar 7, 2012 · Viewed 26.5k times · Source

using the following code in the parent ViewController, I want to present a second view ontop of the first, then dismiss the first:

// Animates the next questionViewController using the first questionViewController
[previousView presentViewController:nextQuestionViewController animated:YES completion:nil];

// Dismiss the first questionViewController
[previousView dismissViewControllerAnimated:NO completion:nil];

When run, the second view is presented, but the first view will not dismiss.

Answer

Bern11 picture Bern11 · May 8, 2012

You would need to first dismiss the "previousView" & then present the "nextQuestionViewController":

// Dismiss the first questionViewController
[previousView dismissViewControllerAnimated:NO completion:nil];

// Animates the next questionViewController using the first questionViewController
[previousView presentViewController:nextQuestionViewController animated:YES completion:nil];