2014-01-24 55 views
0

我很驚訝,這之前沒有被問及和回答..我搜索了幾個小時,找不到答案.. 我有一個tabbarcontroller與6個視圖控制器。因此,顯示的選項卡越多,另外兩個視圖控制器現在駐留在更多視圖中。問題是,我可以將tabbar項目圖像設置爲前4個視圖控制器,但除此之外,我得到一個超出範圍的索引,這是有道理的,因爲其他兩個不再是tabBar.items索引的一部分。將圖像添加到uitabbar控制器的更多導航控制器中的項目

如何將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"; 

enter image description here

回答

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"]]; 
    } 
相關問題