self.title sets navigationController and tabBarItem's title? Why?

IphoneUinavigationcontrollerTabbarcontroller

Iphone Problem Overview


I do this in a UIViewController for one of my tabs:

self.title = @"Welcome";

However, it's overwriting whatever I have for the tabBarItem. I have tried:

self.tabBarItem.title = @"Home";

and

[self.tabBarItem initWithTitle:@"Home" image:[UIImage imageNamed:@"iconHome.png"] tag:0];

But still, self.title overwrites the tabBarItem, regardless of whether I am trying the two latter pieces of code after the title has been set. The code even runs without errors, but the self.tabBarItem.title or initWithTitle doesn't do anything?

Iphone Solutions


Solution 1 - Iphone

OK, I figured it out! Here's what I am doing:

self.title = @"Title for TabBarItem"; // TabBarItem.title inherits the viewController's self.title
self.navigationItem.title = @"Title for NavigationBar";

the navigationBar would inherit self.title, unless otherwise set using self.navigationItem.title

Solution 2 - Iphone

//set nav item title
self.navigationController.navigationBar.topItem.title = @"zurück";

this did it for me :=) (nothing of the above worked)

Solution 3 - Iphone

Try:

[self setTitle:@"Welcome"];

UITabBarItem *item = [[UITabBarItem alloc] initWithTitle:@"Home" image:[UIImage imageNamed: image] tag:0];
[self setTabBarItem:item];
[item release];

Solution 4 - Iphone

I was also facing the same issue, but i solve this issue like this. I set the title and image of tabBarItem right after i created them in appDelegate.

This is what i have done:

[viewController setTitle:@"controllerTitle"];
[[viewController tabBarItem] setTitle:@"Custome Title for tab"];
[[viewController tabBarItem] setImage:[UIImage imageNamed:@"tab.png"]];

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionrunmadView Question on Stackoverflow
Solution 1 - IphonerunmadView Answer on Stackoverflow
Solution 2 - IphonecV2View Answer on Stackoverflow
Solution 3 - IphoneKevinView Answer on Stackoverflow
Solution 4 - IphoneitsaboutcodeView Answer on Stackoverflow