【问题标题】:Set different UINavigationController titles for embedded UITabBar subviews?为嵌入式 UITabBar 子视图设置不同的 UINavigationController 标题?
【发布时间】:2013-12-06 17:59:10
【问题描述】:
在我的应用程序中,我在 UINavigationController 中嵌入了一个 UITabBarController。问题是 UINavigationController 将该选项卡栏视为单个视图控制器,即使其中有 4 个选项卡。我需要为导航栏标题中显示的这 4 个选项卡中的每一个设置不同的标题。在这 4 个视图的子类上使用 self.title 没有任何作用。它只是在导航栏中不断地显示相同的标题,因为就像我说的那样,UINavigationController 将整个标签栏控制器视为单个视图。
如何为标签栏控制器内的每个标签视图设置单独的标题?
【问题讨论】:
标签:
ios
objective-c
uinavigationcontroller
uitabbarcontroller
【解决方案1】:
尝试在每个选项卡的视图控制器中使用[self.navigationItem setTitle:]。如果这不起作用,请尝试更深入,[self.tabBarController.navigationItem setTitle:]。
【解决方案2】:
看起来很直接。
将 UITabBarDelegate 设置为您的 UITabBarController 子类并实现委托方法 -
- (void)tabBar:(UITabBar *)tabBar didSelectItem:(UITabBarItem *)item
在此方法中,根据选定的选项卡设置相应的标题。它应该工作!