Xcode动态添加选项卡栏图标

Xcode动态添加选项卡栏图标,xcode,icons,uitabbarcontroller,uitabbar,uitabbaritem,Xcode,Icons,Uitabbarcontroller,Uitabbar,Uitabbaritem,我在app delegate和interface builder中阅读了关于添加选项卡栏图标的不同答案。我想将它们添加到我的firtsviewcontroller中,因为我想从plist读取图标图像名称。 建议这样做: NSArray *viewControllerArray = nil; viewController1 = <View Init Code> viewController2 = <View Init Code> viewController3 = <

我在app delegate和interface builder中阅读了关于添加选项卡栏图标的不同答案。我想将它们添加到我的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];

有什么解决方案吗?

像这样的解决方案怎么样:

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

在遇到您描述为“更干净的解决方案”的死角之前,请考虑一下用户可能会对选项卡栏项目重新排序(通过更多,编辑)。你的应用程序可能不是这样,但这肯定是SDK开发人员考虑的一个普遍问题。我的应用程序将有5个tabbarItem,它是设计固定的,用户将没有选择重新排列图标。在我的应用程序中重新排列tabbaritem图标没有意义。我想在我的firstviewcontroller中从我的Plist中读取de tabbaricon图像
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:...];