how to change uiviewcontroller title independent of tabbar item title

I am setting my view controllers title like this in view did load:

self.title = @"my title";

prior to this I set the title in story boards for the view controller and navigation controller it is embedded in. I set it to: “Title”;

  • Dismissing a Presented View Controller
  • How to add a slide-in view effect?
  • NSFetchedResultsController: Fetch in a background thread
  • UINavigationBar custom transition animation
  • Programmatically call storyboard in delegate
  • “Presenting view controllers on detached view controllers is discouraged” message when presenting modal
  • When I click on the tab that holds the view controller the title of tab bar item and uiviewcontroller change to: my title

    I would like for the view controller to change but the tab bar item to stay with the title: Title

    How can I accomplish this?

    7 Solutions Collect From Internet About “how to change uiviewcontroller title independent of tabbar item title”

    It sounds like you want the title in the navigation bar to change but not the one in the tabbar. This should do that.

    [self.navigationItem setTitle:@"my title"];
    

    Swift:

    self.navigationItem.title = "My Title"
    

    So for those who still don’t get it (like me)

    self.navigationItem.title = @"my title"; sets navigation bar title.

    self.tabBarItem.title = @"my title"; sets tab bar title.

    self.title = @"my title"; sets both of these.

    For Swift use this,

    self.navigationItem.title = "Navigation bar title" 
    self.title = "Tab bar title"
    

    Swift

    Set top bar title

    self.navigationController?.navigationBar.topItem?.title = "top title"
    

    Set tab item title

    self.tabBarController?.tabBar.items?[0].title = "tab title"
    

    Set both titles

    self.title = "both titles"
    

    I believe in the viewDidLoad method of the view controller you can do:

    self.title = @"my title";
    self.tabBarItem.title = @"tab title";
    

    Pretty late to this. You could have your TabBarController serve as the UITabBarControllerDelegate and UINavigationControllerDelegate for itself and the navigation controllers embedded in each of your tabs respectively.

    .h:

    @interface YourTabBarController : UITabBarController <UITabBarControllerDelegate, UINavigationControllerDelegate>
    
    @end
    

    .m:

    - (void) viewDidLoad {
        // UITabBarControllerDelegate
        self.delegate = self;
    
        // UINavigationControllerDelegates
        yourNavigationController.delegate = self;
        ...
    }
    
    - (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController{
        yourNavigationController.tabBarItem.title = @"Tab Bar Title";
        ...
    }
    
    - (void)navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated {
        yourNavigationController.tabBarItem.title = @"Tab Bar Title";
        ...
    }
    

    Based on some quick testing, it seems like these two delegate actions should cover any loose cases and will update the title whether you’re switching tabs or browsing in your navigation controller. For completeness, you could update your title in didShowViewController as well, but based on what I’ve seen, I don’t think it’s necessary.

    Probably a bit late (but).

    Setting the title of a VC changes the title of the Navigation AND the tabBar.
    (if the VC is already attached to both).

    If you want to have separate titles, you need to manually set those, you normally set the title for the VC and then specifically the title of the tabBarItem, since it’s a property of the