[英]can not name the title for navigation bar after adding segmentcontroller to titleView
My view right now is containing 3 uitabbaritem
. 我现在的观点是包含3 uitabbaritem
。 At the first tab, I am adding a segmentcontroller
to self.navigationItem.titleView
by following 在第一个选项卡上,我增加了segmentcontroller
到self.navigationItem.titleView
通过以下
-(void)viewDidLoad {
// Enable 'segmentControl' on navigation bar
self.navigationItem.titleView = self.segmentedControl;
}
What ends up is 最终是
Next, when I switch to the second uitabbaritem, I hide the segmentcontroller and name the title for the navigation like below 接下来,当我切换到第二个uitabbaritem时,我隐藏了segmentcontroller并为导航的标题命名,如下所示
- (void)tabBar:(UITabBar *)tabBar didSelectItem:(UITabBarItem *)item {
if ( item.tag == 1 ) {
self.navigationItem.titleView.hidden = NO;
}
if ( item.tag == 2 ) {
self.navigationItem.titleView.hidden = YES;
self.title = @"support";
}
}
However, after clicking on the second uitbarbatitem, the title is not displayed on the navigation bar.. 但是,单击第二个uitbarbatitem之后,标题不会显示在导航栏上。
Please advice me if you know what I have done wrong. 如果您知道我做错了什么,请告诉我。 Thanks 谢谢
The title
is not shown when there is a titleView
set, no matter if it's hidden or not. 设置titleView
,无论title
是否隐藏, title
都不会显示。 You have to set the titleView
to nil
. 您必须将titleView
设置为nil
。
- (void)tabBar:(UITabBar *)tabBar didSelectItem:(UITabBarItem *)item {
if ( item.tag == 1 ) {
self.navigationItem.titleView = self.segmentedControl;
self.title = nil;
}
if ( item.tag == 2 ) {
self.navigationItem.titleView = nil;
self.title = @"support";
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.