Setting UITabBarItem title from UINavigationController?
Posted
by
fuzzygoat
on Stack Overflow
See other posts from Stack Overflow
or by fuzzygoat
Published on 2011-01-10T15:04:22Z
Indexed on
2011/01/10
16:53 UTC
Read the original article
Hit count: 198
I have setup a UITabBarController with two tabs, one is a simple UIViewController and the other is a UINavigationController using second UIViewController as its rootController to set up a UITableView. My question is with regard to naming the tabs (i.e. UITabBarItem)
For the first tab (simple UIViewController) I have added the following (see below) to the controllers -init method.
- (id)init {
self = [super init];
if(self) {
UITabBarItem *tabBarItem = [self tabBarItem];
[tabBarItem setTitle:@"ONE"];
}
return self;
}
For the other tab I have added (see below) to the second controllers init (rootController).
- (id)init {
self = [super init];
if(self) {
UITabBarItem *tabBarItem = [[self navigationController] tabBarItem];
[tabBarItem setTitle:@"TWO"];
}
return self;
}
Am I setting the second tabBarItem title in the right place as currently it is not showing?
EDIT:
I can correctly set the UITabBarItem from within the AppDelegate when I first create the controllers, ready for adding to the UITabBarController. But I really wanted to do this in the individual controller -init methods for neatness.
// 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];
© Stack Overflow or respective owner