Wizard style navigation, dismissing a view and showing another one

Posted by Robin Jamieson on Stack Overflow See other posts from Stack Overflow or by Robin Jamieson
Published on 2009-08-13T17:47:07Z Indexed on 2010/04/12 16:03 UTC
Read the original article Hit count: 291

Filed under:

I'm making a set of screens similar to a wizard and I'd like to know how to make a view dismiss itself and its parent view and immediately show a 'DoneScreen' without worrying about resource leaks. My views look like the following:

Base -> Level1 -> DoneScreen
               -> Level2 -> DoneScreen

The Level1 controller is a navigation controller created with a view.xib and shown with

[self presentModalViewController ...]

by the Base controller. The Level1 controller is also responsible for creating the 'DoneScreen' which may be shown instead of the Level2 Screen based on a certain criteria.

When the user taps a button on the screen, the Level1 controller instantiates the the Level2 controller and it displays it via

[self.navigationController pushViewController ..]

and Level2 controller's view has a 'Next' button.

When the use hits the 'Next' button in the Level2 screen, I need to dismiss the current Level2's view as well as the Level1's view and display the 'DoneScreen', which would have been created and passed in to the Level2 controller from Level1. (partly to reduce code duplication, and partly to separate responsibilities among the controllers) In the Level2 controller, if I show the 'DoneScreen' first and dismiss itself with

[self.navigationController popViewControllerAnimated:YES];

then the Level1 controller's modal view is still present above the 'Base' but under the Done screen. What's a good way to clear out all of these views except the Base and then show the 'DoneScreen'?

Any good suggestions on how to get this done in a simple but elegant manner?

© Stack Overflow or respective owner

Related posts about iphone