Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to set individual tabbaritem icons in uitabbarcontroller in cocoa

I was answered how to set images in general for a uitabbarcontroller. however my uitabbarcontroller is an array of views that looks like:

          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, 

I was given the code in the previous answer to add an image to a tabbaritem:

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

However this doesn't specify the specific tabbbaritem.

How do I assign an image to each of these 4 tabs?

Thanks! nil];

like image 298
Atma Avatar asked Jun 10 '09 20:06

Atma


1 Answers

Do it like this for each View Controller that you'll be adding to your Tab Bar:

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

navigationTab1Controller = [[UINavigationController alloc] initWithRootViewController:viewTab1controller];
navigationTab1Controller.tabBarItem.image = [UIImage imageNamed:@"Match.png"];
like image 60
user90864 Avatar answered Oct 21 '22 04:10

user90864