[With YES]
In ViewController
:
- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
self.navigationItem.leftBarButtonItem = nil;
self.navigationController.navigationBar.topItem.title = @"VC 0";
}
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
ViewController1 *controller = segue.destinationViewController;
self.navigationController.navigationBar.topItem.title = @"VC 1";
self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"Back" style:UIBarButtonItemStylePlain target:controller action:@selector(backBtnClicked:)];
}
In ViewController1
:
- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"Back" style:UIBarButtonItemStylePlain target:self action:@selector(backBtnClicked:)];
}
and in its header file, add:
- (void)backBtnClicked:(id)sender;
I noticed that when push from VC0 to VC1, prefersStatusBarHidden
method in VC1 is called before viewWillDisappear
of VC0 is called. I logged the self.navigationController.navigationBar.backItem.title
and self.navigationController.navigationBar.topItem.title
to see what happened. When status bar is hidden in VC1, the logs is different when it is not hidden, when pop back from VC2 to VC1, the backItem becomes nil and topItem becomes the VC0's title. Which shouldn't be, so in order to keep the title of VC1, we need to set the topItem title to VC1's title when VC1 appears.
From here there are rules of displaying leftmost, middle, and right content of navigation bar.
If a custom bar button item is not specified by either of the view
controllers, a default back button is used and its title is set to the
value of the title property of the previous view controller—that is,
the view controller one level down on the stack.
[With NO]
Finishing up a navigation transition in an unexpected state.
Navigation Bar subview tree might get corrupted
This may be caused by concurrent animation, since hiding/showing status bar and popviewController happens at the same time, after you move the code to viewDidDisappear
and viewDidAppear
, the warning disappears.