I installed a UITabBarController with two tabs, one of which is a simple UIViewController and the other is a UINavigationController, using the second UIViewController as its rootController (later this will be used to configure the UITableView). My question is to name the tabs (i.e. set the title of each UITabBarItem)
For the first tab (a simple UIViewController), I added the following (see below) to the -sit method of the controllers.
// FROM -[MapController init] - (id)init { self = [super init]; if(self) { UITabBarItem *tabBarItem = [self tabBarItem]; [tabBarItem setTitle:@"ONE"]; } return self; }
For another tab, I added (see below) to the second initialization of the controllers (rootController).
// FROM -[TableController init] - (id)init { self = [super init]; if(self) { UITabBarItem *tabBarItem = [[self navigationController] tabBarItem]; [tabBarItem setTitle:@"TWO"]; } return self; }
I set the second tabBarItem header in the right place, because currently it is not displayed when I launch the application, the first tab says βONEβ, the second is empty. Also tabBarItem (above) shows nil when I print a value or look through the debugger.
EDIT_001: added full code from AppDelegate
I can set UITabBarItem from AppDelegate correctly when I first create controllers ready to be added to UITabBarController. But I really wanted to do this in a separate controller - based on methods for accuracy.
// UITabBarController UITabBarController *tempRoot = [[UITabBarController alloc] init]; [self setRootController:tempRoot]; [tempRoot release]; NSMutableArray *tabBarControllers = [[NSMutableArray alloc] init]; // UIViewController ONE MapController *mapController = [[MapController alloc] init]; [tabBarControllers addObject:mapController]; [mapController release]; // UITableView TWO TableController *rootTableController = [[TableController alloc] init]; UINavigationController *tempNavController = [[UINavigationController alloc] initWithRootViewController:rootTableController]; [rootTableController release]; [tabBarControllers addObject:tempNavController]; [tempNavController release]; [rootController setViewControllers:tabBarControllers]; [tabBarControllers release]; [window addSubview:[rootController view]]; [window makeKeyAndVisible];
EDIT_002: the solution still updates the UITabBarItems in the application delegate, for example
// TABLE CONTROLLER TableController *tableController = [[TableController alloc] init]; UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:tableController]; [tableController release]; [tabBarControllers addObject:navController]; UITabBarItem *tabBarItem_002 = [navController tabBarItem]; [tabBarItem_002 setTitle:@"TWO"]; [tabBarItem_002 setImage:[UIImage imageNamed:@"GT_TWO.png"]]; [navController release];
EDIT_003: is there a way to set UITabBarItem to a UINavigationController or is the delegate (as it seems) really the best place to do this.