4

我已经阅读了有关在应用程序委托和界面构建器中添加标签栏图标的不同答案。我想将它们添加到我的 firtsviewcontroller 中,因为我想从plist. 建议这样做:

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];

但我不喜欢这样做,因为我认为那不干净。我想做类似于以下的事情,但我不知道为什么它不起作用:

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

有什么解决办法吗?

4

1 回答 1

0

怎么样:

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:...];
于 2013-06-16T17:52:57.993 回答