Decision:
Here's how to fix the problem with the back button of the detail view controller:
- For any view controller that gets on the stack of the main navigation controller, install this
title controller. (Either in the viewDidLoad: method, or in the push-view control method prepareForSegue:sender: ) - Set the
title navigation main controller in the child view control method viewDidLoad:
For example, in MasterViewController.m :
- (void)viewDidLoad { [super viewDidLoad]; [self setTitle:@"Foo"]; } - (void)viewWillAppear:(BOOL)animated { [super viewWillAppear:animated]; [[self navigationController] setTitle:[self title]]; }
This will cause the title of the detail view control button to be synchronized with the title of the top main controller.
What's happening:
UINavigationController , its rootViewController and UINavigationItem have a title property.
Note that the back button displayed for the current view controller is actually the previous backButtonItem view backButtonItem . (See Figure 1-7 Navigation Bar Structure)
A UINavigationController automatically inherits the title value of its root view controller, but will not automatically inherit the title of any other controller that will be pushed onto its stack. This is why, by default, the back button of the detail view controller always displays the title of the root controller of the main navigation controller. You can select, initialize, and click multiple child view controllers, but only one navigation controller is allocated and initialized for each side of the standard controller with a separate view.
In addition, the property view controller navigationItem title (whose value appears on the shortcut in the center of the navigation bar) does not inherit its value from the navigation controller , but from the view controller itself. If you set the view controller property title to โBarโ and the title of the navigation controller โFooโ, โBarโ will be displayed on the label displayed in the center of the navigation bar.
Cybermooai
source share