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! :)