Search code examples
objective-cuinavigationcontrollerhistory

How to clear or resetting UINavigation history?


I have a game setup screen which uses UINavigation and am trying to reset or clear the UINavigation once a person has selected a color.

My app's current process can be best described in the following diagram:

Start application -> New game -> Pick character -> Pick Color -> Start game

Up until "Pick Color" I use the UINavigation, however when a color is picked I want to clear the UINavigation history.

The reason for doing this is so that you can't go back once you've started the game and want the UINavigation to with a clean slate with no indication that you can go back (and this also includes going back to the main menu screen).

The way I am doing it right now is thusly;

[self.navigationController popToRootViewControllerAnimated:YES];

GameDashboardVC *dashboard = [[GameDashboardVC alloc] initWithNibName:@"GameDashboardVC" bundle:nil];
dashboard.title = @"Dashboard"; 
dashboard.managedObjectContext = self.managedObjectContext;

[self.navigationController pushViewController:dashboard animated:YES];

[dashboard release];

The problem is that it pops to the rootViewController but it never pushes the dashboard onto the stack.

I've tried:

[self.parentViewController.navigationController pushViewController....]

The only thing I haven't tried is putting my dashboard push inside the root view controller itself, but I am concerned because I am not sure if it should even be there.

Therefore, where is the correct place to put this kind of functionality, and how do I clear the UINavigation's stack.

Thank you for your time/help.


Solution

  • I solved the problem now to my satisfaction.

    I put the following code inside my initWithNibName method:

    self.navigationItem.hidesBackButton = YES;
    

    This hid the back button and I didn't have to pop anything, but I think for memory reasons it might be useful to keep the idea of removing un-necessary items from the stack.

    But for now the above will do.