我对开发还很陌生。目前我有一个自定义的标签栏(使用每个标签的图像),它完美地工作,还包括一个表格视图和导航视图,然后通向第二个标签栏(我想要不同的标签图像)。当我尝试在第二个标签栏区域中实现相同的代码时,它不起作用,而不是更改第二个标签栏,而是将第一个标签栏更改为我的新图像。如何通过使用相同的代码来阻止这种情况发生,或者我需要如何更改代码(显然第二个标签栏的图像会发生变化)。我确信我可能需要添加或更改一些简单的东西。这是代码:
UIImage *selectedImage0 = [UIImage imageNamed:@"TabImage1DB.png"];
UIImage *unselectedImage0 = [UIImage imageNamed:@"TabImage1LB.png"];
UIImage *selectedImage1 = [UIImage imageNamed:@"TabImage2DB.png"];
UIImage *unselectedImage1 = [UIImage imageNamed:@"TabImage2LB.png"];
UIImage *selectedImage2 = [UIImage imageNamed:@"TabImage3DB.png"];
UIImage *unselectedImage2 = [UIImage imageNamed:@"TabImage3LB.png"];
UIImage *selectedImage3 = [UIImage imageNamed:@"TabImage4DB.png"];
UIImage *unselectedImage3 = [UIImage imageNamed:@"TabImage4LB.png"];
UIImage *selectedImage4 = [UIImage imageNamed:@"TabImage5DB.png"];
UIImage *unselectedImage4 = [UIImage imageNamed:@"TabImage5LB.png"];
UITabBar *tabBar = self.tabBarController.tabBar;
UITabBarItem *item0 = [tabBar.items objectAtIndex:0];
UITabBarItem *item1 = [tabBar.items objectAtIndex:1];
UITabBarItem *item2 = [tabBar.items objectAtIndex:2];
UITabBarItem *item3 = [tabBar.items objectAtIndex:3];
UITabBarItem *item4 = [tabBar.items objectAtIndex:4];
[item0 setFinishedSelectedImage:selectedImage0 withFinishedUnselectedImage:unselectedImage0];
[item1 setFinishedSelectedImage:selectedImage1 withFinishedUnselectedImage:unselectedImage1];
[item2 setFinishedSelectedImage:selectedImage2 withFinishedUnselectedImage:unselectedImage2];
[item3 setFinishedSelectedImage:selectedImage3 withFinishedUnselectedImage:unselectedImage3];
[item4 setFinishedSelectedImage:selectedImage4 withFinishedUnselectedImage:unselectedImage4];
这就是我当前的代码的样子,但它仍然无法正常工作。
UITabBarController *townTabViewController = [[UITabBarController alloc] init];
townTabViewController.view.frame = CGRectMake(0, 0, 320, 460);
// Set each tab to show an appropriate view controller
[townTabViewController setViewControllers:[NSArray arrayWithObjects:townTabViewController, nil]];
// Add the tab controller view to the parent view
[self.view addSubview:townTabViewController.view];
UIImage *selectedImage0 = [UIImage imageNamed:@"HomeDB.png"];
UIImage *unselectedImage0 = [UIImage imageNamed:@"HomeLB.png"];
UIImage *selectedImage1 = [UIImage imageNamed:@"TabImage2DB.png"];
UIImage *unselectedImage1 = [UIImage imageNamed:@"TabImage2LB.png"];
UIImage *selectedImage2 = [UIImage imageNamed:@"TabImage3DB.png"];
UIImage *unselectedImage2 = [UIImage imageNamed:@"TabImage3LB.png"];
UIImage *selectedImage3 = [UIImage imageNamed:@"TabImage4DB.png"];
UIImage *unselectedImage3 = [UIImage imageNamed:@"TabImage4LB.png"];
UIImage *selectedImage4 = [UIImage imageNamed:@"TabImage5DB.png"];
UIImage *unselectedImage4 = [UIImage imageNamed:@"TabImage5LB.png"];
UITabBar *tabBar = self.tabBarController.tabBar;
UITabBarItem *item0 = [tabBar.items objectAtIndex:0];
UITabBarItem *item1 = [tabBar.items objectAtIndex:1];
UITabBarItem *item2 = [tabBar.items objectAtIndex:2];
UITabBarItem *item3 = [tabBar.items objectAtIndex:3];
UITabBarItem *item4 = [tabBar.items objectAtIndex:4];
[item0 setFinishedSelectedImage:selectedImage0 withFinishedUnselectedImage:unselectedImage0];
[item1 setFinishedSelectedImage:selectedImage1 withFinishedUnselectedImage:unselectedImage1];
[item2 setFinishedSelectedImage:selectedImage2 withFinishedUnselectedImage:unselectedImage2];
[item3 setFinishedSelectedImage:selectedImage3 withFinishedUnselectedImage:unselectedImage3];
[item4 setFinishedSelectedImage:selectedImage4 withFinishedUnselectedImage:unselectedImage4];