4

I've read different answers about adding tabbar icons both in the app delegate and in the interface builder.I want to add them in my firtsviewcontroller, because I wanted to read the icon image name from the plist. It is suggested to do like this:

NSArray *viewControllerArray = nil;
viewController1 = <View Init Code>
viewController2 = <View Init Code>
viewController3 = <View Init Code>

1stNavController = [[UINavigationController alloc] initWithRootViewController:viewController1]; 
UIImage *img = [UIImage imageNamed:@"tab_home"];
[1stNavController .tabBarItem initWithTitle:@"Home" image:img tag:1];

But I don't like to do it in this way, because I think that is not clean. I would like to do something similar to the following, but I dont know why it is not working:

[[self.tabBarController.tabBar.items objectAtIndex:2] setIcon:[UIImage imageNamed:....]];

Any solution?

Aitul
  • 2,982
  • 2
  • 24
  • 52
  • 2
    Before running into the deadend you describe as a "cleaner solution", think about the possiblity that a user could potentially reorder the tabbar-items (via more, edit). That might not be the case for your app but it certainly is a general issue the SDK developers thought about. – Till Sep 25 '12 at 19:30
  • My app will have 5 tabbaritems, it is fixed by design, and the user will not have the choice to reorder the icons. It has no sense to reorder the tabbaritem icons in my app.I want to read de tabbaricon image from my Plist in my firstviewcontroller – Aitul Sep 25 '12 at 19:34

1 Answers1

0

How about something like:

NSArray *viewControllers = self.tabBarController.viewControllers;
((UIViewController*)viewControllers[0]).tabBarItem.image = [UIImage imageNamed:...];
((UIViewController*)viewControllers[1]).tabBarItem.image = [UIImage imageNamed:...];
((UIViewController*)viewControllers[2]).tabBarItem.image = [UIImage imageNamed:...];
((UIViewController*)viewControllers[3]).tabBarItem.image = [UIImage imageNamed:...];
((UIViewController*)viewControllers[4]).tabBarItem.image = [UIImage imageNamed:...];
Jacob Lukas
  • 689
  • 6
  • 14