Question

I'm pushing to a few viewcontrollers with my UINavigationController and when I'm on my 3rd UISubViewController I coded to 'popToRootViewController' and it pop's back, but the navigationbar-items push to the 2nd view controller not to the 1st..

  • I tried it with and without animating, but nothing is gonna change.
  • I tried to say self.navigationController.navigationBar pop back, but it do nothing on my bar.

Thanks for help..

Was it helpful?

Solution

I am a little confused at your question but I think this should help. As far as I know you can't have the "back" button on a UINavigationController go back more than 1 pop. So what you do is you have to add another button that does the popToRootViewController function. Try something like this:

UIBarButtonItem *newButton = [[UIBarButtonItem alloc] initWithTitle:@"Home" style:UIBarButtonItemStylePlain target:self action:@selector(homeAction:)];

self.navigationItem.rightBarButtonItem = newButton;

This will add a button to the right on your navigation controller. The next step is to add a function called whatever you name in the action (in this case it needs to be called "homeAction"). This looks like so:

-(IBAction)homeAction:(id)sender {
      [self.navigationController popToRootViewControllerAnimated:YES];
}

This should cover the pop back to the root of the controller where ever you are in the stack. You will also have to IBAction method to your .h file but other than that it should do everything you want to.

OTHER TIPS

unless you are doing something odd with the array of UIViewControllers of NavigationController, the method should be:

[self.navigationController popToRootViewControllerAnimated:YES];
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top