![](/img/trans.png)
[英]How to set title of Navigation Bar from a View Controller of a subview?
[英]How to set the navigation bar title from view controllers inside tabs?
我在导航控制器中嵌入了标签栏控制器。 我想在选项卡内的视图控制器中在导航中设置标题。
如果我使用:
self.title = "ABC";
要么
self.tabBarItem.title = "ABC";
底部标签的标题设置为“ ABC”,而不是顶部导航栏中的标题。
但是,我只想在导航栏中设置标题,而不是底部的标签。
我怎样才能做到这一点?
您可以使用self.navigationItem.title
进行设置。
self.navigationItem.title=@"ABC";
您必须将navigationItem向上传递。
UINavigationController显示属于其topViewController的navigationItem,它是UITabBarController。
UITabBarController在其选项卡中显示navigationItem标题。 因此,您需要做的是确保tabBarController的navigationItem是selectedViewController的navigationItem
总结一下:
UINavigationController title = topViewController.navigationItem.title
UITabBarController tabTitle = selectedViewController.navigationItem.title
UIViewController title = navigationItem.title
您可能使用了错误的元素,请尝试以下示例:
self.tabBarController.title = @"YOUR_TITLE";
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.