How to change the tab bar item title at apps delegate. Currently I have 5 tab bar item. How to change the 5 tab bar item title programmatically at startup?
My tab bar controller
is set up as follow. I have 5 tab bar controller
and 4 of which is embedded in a navigation controller
. Then I have one which is a standalone ViewController
Please help.
Updated according to Atanu Mondal answer
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
[self setUpTabBar];
[self setUpTabBarSettings];
}
-(void)setUpTabBar{
UITabBarController *tabBarController = [[UITabBarController alloc] init];
tabBarController.tabBar.barTintColor = [UIColor redColor];
tabBarController.tabBar.tintColor = [UIColor yellowColor];
NSMutableArray *arrControllers=[NSMutableArray array];
[arrControllers addObject:[self navControlWithRootVC:1]];
[arrControllers addObject:[self navControlWithRootVC:2]];
[arrControllers addObject:[self navControlWithRootVC:3]];
[arrControllers addObject:[self navControlWithRootVC:4]];
[arrControllers addObject:[self navControlWithRootVC:5]];
[tabBarController setViewControllers:arrControllers];
[self.window setRootViewController:tabBarController];
[self.window makeKeyAndVisible];
}
-(UINavigationController *)navControlWithRootVC:(int)index{
id viewController_;
switch (index) {
case 1:
viewController_=[[UIViewController alloc] initWithNibName:@"ViewController1" bundle:nil];
break;
case 2:
viewController_=[[UIViewController alloc] initWithNibName:@"ViewController" bundle:nil];
break;
case 3:
viewController_=[[UIViewController alloc] initWithNibName:@"ViewController3:" bundle:nil];
break;
case 4:
viewController_=[[UIViewController alloc] initWithNibName:@"ViewController4" bundle:nil];
break;
case 5:
viewController_=[[UIViewController alloc] initWithNibName:@"ViewController5" bundle:nil];
break;
default:
viewController_=[[UIViewController alloc] init];
break;
}
UINavigationController *navControl = [[UINavigationController alloc] initWithRootViewController:viewController_];
return navControl;
}
-(void)setUpTabBarSettings{
tabBar = self.tabBarController.tabBar;
tabBarItem1 = [tabBar.items objectAtIndex:0];
tabBarItem2 = [tabBar.items objectAtIndex:1];
tabBarItem3 = [tabBar.items objectAtIndex:2];
tabBarItem4 = [tabBar.items objectAtIndex:3];
tabBarItem5 = [tabBar.items objectAtIndex:4];
tabBarItem1.title = @"Title 1";
tabBarItem2.title = @"Title 2";
tabBarItem3.title = @"Title 3";
tabBarItem4.title = @"Title 4";
tabBarItem5.title = @"Title 5";
}