Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to present a second ViewController & dismiss the first

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.

like image 545
Tim Windsor Brown Avatar asked Mar 07 '12 12:03

Tim Windsor Brown


2 Answers

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];
like image 81
Bern11 Avatar answered Nov 15 '22 19:11

Bern11


try

[self dismissViewControllerAnimated:NO completion:nil];

failing that:

[self.navigationController popViewControllerAnimated:YES];
like image 39
ader Avatar answered Nov 15 '22 21:11

ader