How do I reset a UINavigationController?

iphone, uinavigationcontroller

Solution

I have several VCs in my stack as set-up screens before I move to the true home screen.

I got mine to work like this:

HomeViewController *hvc = [[HomeViewController alloc] init];
[self.navigationController pushViewController:hvc animated:YES];
self.navigationController.viewControllers = [[NSArray alloc] initWithObjects:hvc, nil];

I push the HomeViewController and then rewrite the stack to only have the home screen.

Problem

I have a problem involving the UINavigationController. I have a application that have three view controllers that I'm switching between using the navigation controllers push and pop functionality. The problem is this: I stand in the third view controller and makes a call to [self.navigationController popToRootViewControllerAnimated:YES]; this brings me to the first view controller (which is exactly what I want) but when I then try to navigate to the second view controller I end up in the third for some reason. Is there any way you can reset the navigation controller, or am I doing this the wrong way? Here is the code that I'm using to push and pop the navigation controller: The following code is called in the root view controller when the user decides to launch the camera. ``` if(self.cameraViewController == nil) { CollageCameraViewController *camView = [[CollageCameraViewController alloc] init];//WithNibName:nil bundle:[NSBundle mainBundle]]; self.cameraViewController = camView; [camView release]; } [self.navigationController pushViewController:self.cameraViewController animated:NO]; ``` The following code is called from CollageCameraViewController (second) after the user has taken his fotos: ``` if(self.renderView == nil) { CollageRenderViewController *renderViewController = [[CollageRenderViewController alloc] initWithNibName:nil bundle:[NSBundle mainBundle]]; self.renderView = renderViewController; [renderViewController release]; } [self.navigationController pushViewController:self.renderView animated:YES]; ``` The following code is called from CollageRenderViewController when the user decides to go back to main (root) view: ``` [self.navigationController popToRootViewControllerAnimated:YES]; ``` Now, if I try to push CollageCameraViewController again I end up in CollageRenderViewController instead, why is that? Cheers, Andreas

Original source