I’m new in iOS development and this may be a very basic question- in my app i’ve 5 VC with UITabBarController on each VC. I’m handling tab bar item click by-
- (void)tabBar:(UITabBar *)tabBar didSelectItem:(UITabBarItem *)item
{
switch (item.tag)
{
case 0:
{
vc1 = [[VC1 alloc] initWithNibName:@"VC1" bundle:nil];
[self.view addSubview:vc1.view];
[tabbarObj setSelectedItem:[tabbarObj.items objectAtIndex:0]];
}
break;
case 1:
{
vc2 = [[VC2 alloc] initWithNibName:@"VC2" bundle:nil];
[self.view addSubview:vc2];
}
break;
case 2:
{
vc3 = [[VC3 alloc] initWithNibName:@"VC3" bundle:nil];
[self.view addSubview:vc3];
}
break;
case 3:
{
[tabbarObj setSelectedItem:[tabbarObj.items objectAtIndex:3]];
}
break;
case 4:
{
vc5 = [[VC5 alloc] initWithNibName:@"VC5" bundle:nil];
[self.view addSubview:vc5];
}
break;
default:
break;
}
}
and i know this is not a right way to handle tab bar because every time when i click on a tab bat item it will add a subView on current view.
Can anybody suggest me a better way?Thanks.
in Your
Appedelegate.mfile Make changes indidFinishLaunchingWithOptionsMethodTo Access Some properties after Your ViewController is Selected Use the following Code.
For Changing Background image of tabbar Controller you can use Following Code.