2009-06-10 5 views
4

On m'a répondu comment définir des images en général pour un contrôleur de uitabbarcontroller. mais mon UITabBarController est un tableau de vues qui ressemble à:comment définir des icônes de tabbaritem individuels dans uitabbarcontroller dans le cacao

  tabBarController = [[UITabBarController alloc] init];   

viewTab1controller = [[ViewTab1Controller alloc] initWithNibName:@"ViewTab1" bundle:nil]; 
viewTab1controller.title = @"Schedules"; 
navigationTab1Controller = [[[UINavigationController alloc] initWithRootViewController:viewTab1controller] autorelease]; 
[viewTab1controller release]; 

viewTab2controller = [[ViewTab2Controller alloc] initWithNibName:@"ViewTab2" bundle:nil]; 
viewTab2controller.title = @"Nearest Stop"; 
navigationTab2Controller = [[[UINavigationController alloc] initWithRootViewController:viewTab2controller] autorelease]; 
[viewTab2controller release]; 

viewTab3controller = [[ViewTab3Controller alloc] initWithNibName:@"ViewTab3" bundle:nil]; 
viewTab3controller.title = @"Routes"; 
navigationTab3Controller = [[[UINavigationController alloc] initWithRootViewController:viewTab3controller] autorelease]; 
[viewTab3controller release]; 

viewTab4controller = [[ViewTab4Controller alloc] initWithNibName:@"ViewTab4" bundle:nil]; 
viewTab4controller.title = @"Feedback"; 
navigationTab4Controller = [[[UINavigationController alloc] initWithRootViewController:viewTab4controller] autorelease]; 
[viewTab4controller release]; 

//viewTab5controller = [[ViewTab5Controller alloc] initWithNibName:@"ViewTab5" bundle:nil]; 
//navigationTab5Controller = [[[UINavigationController alloc] initWithRootViewController:viewTab5controller] autorelease]; 
//[viewTab5controller release]; 

tabBarController.viewControllers = [NSArray arrayWithObjects: 
            navigationTab1Controller, 
            navigationTab2Controller, 
            navigationTab3Controller, 
            navigationTab4Controller, 
            //navigationTab5Controller, 

m'a donné le code dans la réponse précédente pour ajouter une image à un tabbaritem:

 viewController.tabBarItem.image = [UIImage imageNamed:@"foo.png"]; 

Toutefois, cela ne précise pas la tabbbaritem spécifique.

Comment attribuer une image à chacun de ces 4 onglets?

Merci! nul];

Répondre

17

Est-ce comme ça pour chaque contrôleur de vue que vous ajouterez à votre barre d'onglets:

viewTab1controller = [[ViewTab1Controller alloc] initWithNibName:@"ViewTab1" bundle:nil]; 
viewTab1controller.title = @"Schedules"; 

navigationTab1Controller = [[UINavigationController alloc] initWithRootViewController:viewTab1controller]; 
navigationTab1Controller.tabBarItem.image = [UIImage imageNamed:@"Match.png"]; 
+4

Merci! Bien que cette autorelease est inutile. – pt2ph8

+0

Code édité et enlevé la autorelease - qui était juste un bug. Avec ARC, cela devrait être obsolète maintenant de toute façon, cependant. – Eiko

Questions connexes