Tabbar项目图像未首次加载

时间:2017-02-21 11:59:42

标签: ios objective-c uitabbarcontroller uitabbar uitabbaritem

我在项目中使用tabbarcontroller。这是我的故事板

enter image description here


在所有视图控制器标签栏项目中,我设置如下图像


enter image description here

我制作了一类tabbarcontroller并在下面做了编码

    UITabBar *tabBar = self.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 setImage:[[UIImage imageNamed:@"ic_home_tab_home_sel"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]];
//    [tabBarItem1 setSelectedImage:[[UIImage imageNamed:@"ic_home_tab_home_sel"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]];




    [tabBarItem1 setFinishedSelectedImage:[UIImage imageNamed:@"ic_home_tab_home_sel"] withFinishedUnselectedImage:[UIImage imageNamed:@"ic_home_tab_home"]];
    [tabBarItem2 setFinishedSelectedImage:[UIImage imageNamed:@"ic_home_tab_profile_sel"] withFinishedUnselectedImage:[UIImage imageNamed:@"ic_home_tab_profile"]];
    [tabBarItem3 setFinishedSelectedImage:[UIImage imageNamed:@"ic_home_create_post_sel"] withFinishedUnselectedImage:[UIImage imageNamed:@"ic_home_create_post"]];
    [tabBarItem4 setFinishedSelectedImage:[UIImage imageNamed:@"ic_home_tab_chat_sel"] withFinishedUnselectedImage:[UIImage imageNamed:@"ic_home_tab_chat"]];
    [tabBarItem5 setFinishedSelectedImage:[UIImage imageNamed:@"ic_home_tab_setting_sel"] withFinishedUnselectedImage:[UIImage imageNamed:@"ic_home_tab_setting"]];

但是当我运行它时,enter image description here

第一次所有图像都是混合的,但是当我像Video中一样逐个点击它们时,所有图像都会被设置。 br />我不知道为什么会这样?
请帮帮我
谢谢

1 个答案:

答案 0 :(得分:0)

我也遇到了同样的问题,然后我在appdelegate

中使用了以下代码
 UINavigationController *navigationVC1 = [[UINavigationController alloc]initWithRootViewController:viewController1];
    navigationVC1.tabBarItem = [[UITabBarItem alloc] initWithTitle:@"My Trips"
                                                             image:[UIImage imageNamed:@"cab.png"]
                                                               tag:1];

    UINavigationController *navigationVC2 = [[UINavigationController alloc]initWithRootViewController:viewController2];
    navigationVC2.tabBarItem = [[UITabBarItem alloc] initWithTitle:@"My Children"
                                                             image:[UIImage imageNamed:@"kids-couple.png"]
                                                               tag:2];

试试这样。