I am developing an app but have yet to get the optimal navigation flow working.
To give you an idea of the structure of my app, I have a main view that allows the user to start a new game or view high scores. At the end of a game, I would like to give the user the choice of viewing high scores or going back to the main menu – I have a game over view for this.
The hierarchy looks something like this:
Main View
|
+--Game View
| |
| +--Game Over View
| |
| +--High Scores View
|
+--High Scores View
I am using the presentModalViewController method to switch from the game view to the game over view. This is fine, but when I want to go back to the main view I have two layers of views to navigate through (I want to close the game over view AND the game view to return straight to the main view). To close views I am using dismissModalViewControllerAnimated but this is not ideal for traversing more than one view. Is there a way of replacing the current model view rather than opening a new one on top?
I hope this makes sense. Please let me know if you need anymore details.
Thanks in advance for any help.
Alan
In addition to Alexsander’s great suggestion, you can eschew the use of
presentModelViewController:animated:altogether. Instead, just set therootViewControllerproperty of the activeUIWindow.After setting
aViewControlleras therootViewController, call[aViewController.view becomeFirstResponder];to enable it to respond to touch input.If
presentModelViewController:animated:is like calling a method, settingrootViewControlleris like a goto. I think a “goto” could be more appropriate here because of the cyclic nature of the order in which views can be presented:Main View -> Game View -> Game Over View -> Main View -> Game View -> Game Over View -> etc.