Alex Rivera | Logout

iPhone - dismiss multiple ViewControllers

Asked 2010-05-31T14:37:23.790
47

I have a long View Controllers hierarchy;

in the first View Controller I use this code:

SecondViewController *svc = [[SecondViewController alloc] initWithNibName:@"SecondViewController" bundle:nil];
[self presentModalViewController:svc animated:YES];    
[svc release];

In the second View Controller I use this code:

ThirdViewController *tvc = [[ThirdViewController alloc] initWithNibName:@"ThirdViewController" bundle:nil];
[self presentModalViewController:tvc animated:YES];    
[tvc release];

and so on.

So there is a moment when I have many View Controllers and I need to come back to the first View Controller. If I come back one step at once, I use in every View Controller this code:

[self dismissModalViewControllerAnimated:YES];

If I want to go back directly from the, say, sixth View Controller to the first one, what I have to do to dismiss all the Controllers at once?

Thanks

Edit
Report

1 Answer

0

Dismiss the top VC animated and the other ones not. If you hace three modal VC

[self dismissModalViewControllerAnimated:NO]; // First
[self dismissModalViewControllerAnimated:NO]; // Second
[self dismissModalViewControllerAnimated:YES]; // Third

EDIT: if you want to do this only with one method, save you hierarchy into an array of VC and dismiss the last object animated and the other ones not.

answered 2010-05-31T14:53:45.900

Your Answer