UITabbarController showing only first tab

烂漫一生 提交于 2019-12-11 07:36:36

问题


I manually added UITabbarController in storyboard which is not root view controller. I added tabbar items to it and set segue relationships. I also set image and title of each tabbar item in code when the first view controller of UITabbarController is about to be presented but no matter what I do only the first item's image is visible. Other items images become visible only when they are tapped and their views are actually loaded. Any inputs how to fix it ?

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
// Get the new view controller using [segue destinationViewController].
// Pass the selected object to the new view controller.

if ([segue.identifier isEqualToString:@"AfterLogin"]) {

    UITabBarController *tabBarController = [segue destinationViewController];
    NSArray *tabBarItems = tabBarController.tabBar.items;

    UITabBarItem *item1 = tabBarItems[0];
    UITabBarItem *item2 = tabBarItems[1];
    UITabBarItem *item3 = tabBarItems[2];
    UITabBarItem *item4 = tabBarItems[3];

    [item1 setImage:[[UIImage imageNamed:@"image1_static"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]];
    [item1 setSelectedImage:[[UIImage imageNamed:@"image1_active"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]];
    item1 = @"";
    item1.imageInsets = UIEdgeInsetsMake(6, 0, -6, 0);

    [item2 setImage:[[UIImage imageNamed:@"image2_static"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]];
    [item2 setSelectedImage:[[UIImage imageNamed:@"image1_active"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]];
    item2.title = @"";
    item2.imageInsets = UIEdgeInsetsMake(6, 0, -6, 0);

    [item3 setImage:[[UIImage imageNamed:@"image3_static"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]];
    [item3 setSelectedImage:[[UIImage imageNamed:@"image3_active"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]];
    item3.title = @"";
    item3.imageInsets = UIEdgeInsetsMake(6, 0, -6, 0);

    [item4 setImage:[[UIImage imageNamed:@"image4_static"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]];
    [item4 setSelectedImage:[[UIImage imageNamed:@"image4_active"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]];
    item4.title = @"";
    item4.imageInsets = UIEdgeInsetsMake(6, 0, -6, 0);
}


} 

来源:https://stackoverflow.com/questions/36719197/uitabbarcontroller-showing-only-first-tab

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!