Reputation: 2648
I'm currently learning iOS development and I'm getting confused how titles are being set internally.
I have the following code in a Window-based template for iPad, and I'm doing everything from scratch without the Interface Builder:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
UISplitViewController *svc = [[UISplitViewController alloc] init];
UINavigationController *leftNav = [[UINavigationController alloc] init];
UIViewController *leftView = [[LeftViewController alloc] init];
[leftNav pushViewController:leftView animated:NO];
[leftView release];
UINavigationController *rightNav = [[UINavigationController alloc] init];
UIViewController *rightView = [[RightViewController alloc] init];
[rightNav pushViewController:rightView animated:NO];
[rightView release];
UITabBarController *tbc = [[UITabBarController alloc] init];
tbc.viewControllers = [NSArray arrayWithObjects:leftNav, nil];
[leftNav release];
svc.viewControllers = [NSArray arrayWithObjects:tbc, rightNav, nil];
[tbc release]; [rightNav release];
self.window.rootViewController = svc;
[self.window makeKeyAndVisible];
return YES;
}
I want to have a custom short title for the TabBarItem for LeftViewController, and a long title for the NavigationController bar on top. After a few attempts, I noticed that the following is actually working (code is from LeftViewController:viewDidLoad):
self.title = @"Long title for navigation controller";
self.navigationController.title = @"Short title";
However, I have no idea why setting the navigationController.title sets the title for the TabBarItem. I tried "self.tabBarItem.title = @"Short title" instead, and it doesn't work, which is even more strange.
Can someone explain why this works and how can I set the titles directly and properly, because this really doesn't look right to me, and I feel that I'm missing something important. Thank you! :)
Upvotes: 2
Views: 1343
Reputation: 12325
Apple has made the title
for tabBarItems
and NavigationControllers
the same. Its because most people use this fashion and it saves some time for the developers.
What you can do is create your own Navigation Bar as an outlet for that view and change the title for it (you can do this in the the interface builder if you are using one).. or just set in in the viewDidLoad
method.
self.yourNavigationBar.topItem.title = @"My New Title";
Upvotes: 4