0

My view right now is containing 3 uitabbaritem. At the first tab, I am adding a segmentcontroller to self.navigationItem.titleView by following

-(void)viewDidLoad {

    // Enable 'segmentControl' on navigation bar
    self.navigationItem.titleView               =   self.segmentedControl;
}

What ends up is

enter image description here

Next, when I switch to the second uitabbaritem, I hide the segmentcontroller and name the title for the navigation like below

- (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.. enter image description here

Please advice me if you know what I have done wrong. Thanks

tranvutuan
  • 6,089
  • 8
  • 47
  • 83

1 Answers1

1

The title is not shown when there is a titleView set, no matter if it's hidden or not. You have to set the titleView to 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";
  }
}
Jörn Eyrich
  • 5,141
  • 1
  • 19
  • 14