标签栏图像未显示

时间:2014-03-04 13:31:14

标签: ios uitabbarcontroller

我的代码如下:

UITabBar *tabBar = (UITabBar *)_tabbBarControllr.tabBar;


UITabBarItem *chatItem = [tabBar.items objectAtIndex:0];

[chatItem setImage:[UIImage imageNamed:@"ChatDeselect.png"]];
[chatItem setSelectedImage:[UIImage imageNamed:@"Chatselect.png"]];


//tab2
 UITabBarItem *groupItem = [tabBar.items objectAtIndex:1];

[groupItem setImage:[UIImage imageNamed:@"GropuChatDeselect.png"]];
[groupItem setSelectedImage:[UIImage imageNamed:@"GropuChatSelect.png"]];


//tab3
UITabBarItem *settingsItem = [tabBar.items objectAtIndex:2];

[settingsItem setImage:[UIImage imageNamed:@"SettingsDeselect.png"]];
[settingsItem setSelectedImage:[UIImage imageNamed:@"SettingsSelect.png"]];

图片未显示所选&取消选择状态。 有人可以建议我吗?

1 个答案:

答案 0 :(得分:0)

尝试将项目设置为相关的视图控制器,如下所示 - 假设您可以获取每个相关的视图控制器:

UITabBarItem *chatItem = [tabBar.items objectAtIndex:0];

[chatItem setImage:[UIImage imageNamed:@"ChatDeselect.png"]];
[chatItem setSelectedImage:[UIImage imageNamed:@"Chatselect.png"]];

// Setting here, admitting that you have created this controller before
yourViewController.tabBarItem = chatItem;

然后,以这种方式将所有这些ViewControllers分配给你的UITabBarController,用它们创建一个数组:

yourTabBarController.viewControllers = @[yourViewCtrl1, yourViewCtrl2, yourViewCtrl3];