Navigation bar not refreshed when going to root controller

I have a story pane created like this:

  • Navigation controller --- connected to ---> View A ---> table cell segue ---> View B
  • Standalone C browsing i.e. no other view in the storyboard is connected to it.

I click on a cell in View A, which automatically segue to view B. In view B, after view view and the application event fires, it automatically dismiss itself and pops an instance of View C, doing something like this:

View B:

- (void)someEvent
{
    ViewCController *controller = [self.storyboard instantiateViewControllerWithIdentifier:@"ViewC"];
    [self.navigationController pushViewController:controller animated:YES];
}

      

This works fine, View C appears. However, when I click the back button on the navigation bar in C view, I want it to revert entirely to A view, not B view. I've tried this:

View C:

- (void)viewWillDisappear:(BOOL)animated
{
     [super viewWillDisappear:animated];
     [self.navigationController popToRootViewControllerAnimated:animated];
}

      

This works almost as expected, in that View C is rejected and View A is backtracked bypassing View B. The problem is that the navigation bar in View A still thinks it is one level deeper because it is everything still shows the back button, not the ones shown in A. I need to hit the back button again to display the correct buttons.

What am I missing?

+3


source to share


2 answers


I'm not sure if you can do this or what you should do. The back button has a specific purpose - to go back to the previous view controller, and I don't think you should try to subvert this (its title will point to that one, not your first one). It would be better to add another button on the navbar in viewC and link it to the code that popToRootViewController executes.



+1


source


In C view, highlight your own barButtonItem and put it in self.navigationItem.leftBarButtonItem

to replace the back button and take action of that button[self.navigationController popToRootViewControllerAnimated:YES]



+1


source







All Articles