views:

264

answers:

2

I'd like to be able to give my views short names for display on the tab bar, and longer (more descriptive) name when the same view is linked to in a table view. The reason is that longer names nudge up against each other on the tab bar. In a table view, there's more horizontal space, so I want to use more descriptive titles there.

Normally, the tab bar's title is set in its view controller with self.title. Is there a way to specifically set the tab bar title, but leave the view controller's self.title alone?

Thanks.

A: 

Short and sweet, in your view controller's viewDidLoad:

[[self tabBarItem] setTitle:@"Short Title"];
iKenndac
But you should use the dot-notation for properties; self.tabBarItem.title = @"Short Title";
PeyloW
@PeyloW No, you ***shouldn't*** use dot-notation for properties. You ***can*** use dot-notation for properties, but there is no "should" or "shouldn't" about it.
Dave DeLong
@PeyloW Did you vote me down for not using dot-notation? If so, please undo the vote because you're very wrong - dot-notation is a completely optional language feature, very separate from properties.
iKenndac
I totally agree with Dave and iKenndac! It's simply a matter of taste whether you use message or dot notation. The compiler translates the latter into the former.In my answer I used the dot notation because it is a lot shorter and more familiar to non-Objective-C programmers.
racha
+4  A: 

The information that is displayed in a UITabBar is queried from each UIViewController's tabBarItem" property. Similarly, a UINavigationBar queries the UIViewController's navigationItem for information.

Setting two different titles would work like this (from within you UIViewController):

self.tabBarItem.title = @"TabTitle";
self.navigationItem.title = @"NavigationTitle";

You can also specify other details like the tab bar image or the title on the "back button" via these properties.

racha