我很惊讶以前没有被问过和回答过..我搜索了几个小时但找不到答案.. 我有一个带有6个viewcontrollers的tabbarcontroller。因此,显示的选项卡越多,其他两个视图控制器现在位于更多视图中。问题是,我可以将tabbar项目图像设置为前4个视图控制器,但除此之外的任何东西我得到一个超出范围的索引,这是有道理的,因为其他两个不再是tabBar.items索引的一部分。
如何将tabbar项目图像添加到更多控制器中的项目?
UITabBar *tabBar = tbc.tabBar;
UITabBarItem *tabBarItem1 = [tabBar.items objectAtIndex:0];
UITabBarItem *tabBarItem2 = [tabBar.items objectAtIndex:1];
UITabBarItem *tabBarItem3 = [tabBar.items objectAtIndex:2];
UITabBarItem *tabBarItem4 = [tabBar.items objectAtIndex:3];
UITabBarItem *tabBarItem5 = [tabBar.items objectAtIndex:4];
tabBarItem1.selectedImage = [[UIImage imageNamed:@"news"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
tabBarItem1.image = [[UIImage imageNamed:@"news"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
tabBarItem1.title = @"Reports";
tabBarItem2.selectedImage = [[UIImage imageNamed:@"content"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
tabBarItem2.image = [[UIImage imageNamed:@"content"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
tabBarItem2.title = @"Media Articles";
tabBarItem3.selectedImage = [[UIImage imageNamed:@"map_marker"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
tabBarItem3.image = [[UIImage imageNamed:@"map_marker"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
tabBarItem3.title = @"Map of Reports";
tabBarItem4.selectedImage = [[UIImage imageNamed:@"twitter"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
tabBarItem4.image = [[UIImage imageNamed:@"twitter"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
tabBarItem4.title = @"BFRO News";
tabBarItem5.selectedImage = [[UIImage imageNamed:@"help"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
tabBarItem5.image = [[UIImage imageNamed:@"help"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
tabBarItem5.title = @"FAQs";
答案 0 :(得分:0)
我明白了。我可以使用以下代码将图像添加到更多表格中:
UITableView *view = (UITableView *)tabBarController.moreNavigationController.topViewController.view;
if ([[view visibleCells] count] > 0) {
[[[[view visibleCells] objectAtIndex:0] imageView] setImage:[UIImage imageNamed:@"help"]];
[[[[view visibleCells] objectAtIndex:1] imageView] setImage:[UIImage imageNamed:@"camping_tent"]];
}