根据选择的标签更改导航栏的标题?
我有一个iOS应用程序,其中有一个导航控制器作为根控制器,但在一个部分有一个标签栏,可以在其中一个导航栏中选择视图。它看起来类似于iTunes应用程序(顶部的导航栏,底部的标签栏)。我希望导航栏的标题根据选择的选项卡进行更改。我为每个选项卡分别有两个控制器文件。以下是我到目前为止尝试使用的内容,以解决此问题无效:
I have an iOS app where there is a navigation controller as the root controller but at one part there is a tab bar to select between views in one of the nav bars. It looks similar to the iTunes app (navigation bar on top, tab bar on the bottom). I want the title of my navigation bar to change based on which tab is selected. I have two separate controller files for each tab. Here is what I have tried to use in each so far to fix this to no avail:
self.navigationItem.title = @"Title";
self.navigationController.navigationItem.title = @"title";
[self.navigationController setTitle:@"Live"];
[self setTitle:@"Top Title"];
如何根据按下哪个标签更改NavBar标题?
How do I change the NavBar title based on which tab is pressed?
您可以在当前显示的视图控制器中更改栏的标题。
You change the title of the bar in the view controller that is currently being displayed.
例如,在您在标签控制器中显示的视图控制器A中,您可以添加:
So for example, in view controller A that you're showing in the tab controller, you might add:
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:YES];
[self setTitle:@"A"];
self.tabBarController.navigationItem.title = @"A";
}
B,C等也一样。