Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UITabbar items not showing until click following upgrade to Xcode 7

I have a UITabBar that was functioning well prior to my upgrade to Xcode 7 and now I can't figure out what's going on for the life of me. I've tried several solutions including setting the imageWithRenderingMode for each tab I create, trying to change the background color of the UITabBar to see if maybe the items were just white, and updating the icons themselves to new versions. My default selected tab shows up just fine, and then when I select another tab, the text shows up, but no image. ( The text persists and changes to the default gray when moving to another tab as well. )

I've attached a screenshot of what I'm seeing, and here's how I'm currently implementing the tabbar.

Function to create tabbar:

void MakeTabBar(id target)
{
    PFUser *currentUser = [PFUser currentUser];

    AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
    appDelegate.recentView = [[RecentView alloc] init];
    appDelegate.groupsView = [[GroupsView alloc] init];
    appDelegate.settingsView = [[SettingsView alloc] init];
    appDelegate.homeView = [[HomeView alloc] init];

    NavigationController *navController1 = [[NavigationController alloc] initWithRootViewController:appDelegate.recentView];
    NavigationController *navController2 = [[NavigationController alloc] initWithRootViewController:appDelegate.groupsView];
    NavigationController *navController4 = [[NavigationController alloc] initWithRootViewController:appDelegate.settingsView];
    NavigationController *navController5 = [[NavigationController alloc] initWithRootViewController:appDelegate.homeView];

    appDelegate.tabBarController = [[UITabBarController alloc] init];
    appDelegate.tabBarController.tabBar.translucent = NO;
    appDelegate.tabBarController.selectedIndex = DEFAULT_TAB;
    [[UITabBar appearance] setTintColor:COLOR_OUTGOING];

    NSMutableDictionary *customAttributes = [NSMutableDictionary dictionary];
    BOOL isAdmin = [currentUser[@"isAdmin"] boolValue];
    if(isAdmin){
        [customAttributes setObject:currentUser[@"isAdmin"] forKey:@"isAdmin"];
        appDelegate.peopleView = [[PeopleView alloc] init];
        NavigationController *navController3 = [[NavigationController alloc] initWithRootViewController:appDelegate.peopleView];
        appDelegate.tabBarController.viewControllers = @[navController5, navController1, navController2, navController3, navController4];
    } else{
        appDelegate.tabBarController.viewControllers = @[navController5, navController1, navController2, navController4];
    }

    BOOL isTester = [currentUser[@"isTestData"] boolValue];
    if(isTester){
        [customAttributes setObject:currentUser[@"isTestData"] forKey:@"isTestData"];
    }

    [appDelegate.window setRootViewController:appDelegate.tabBarController];
}

Code in each view to create tab:

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    {
        [self.tabBarItem setImage:[UIImage imageNamed:@"tab_consultants"]];
        self.tabBarItem.title = @"Consultants";
    }
    return self;
}

enter image description here

like image 736
Jake Lisby Avatar asked Sep 21 '15 14:09

Jake Lisby


2 Answers

After tons of trial and error I found the issue was due to navigation controllers and my tabbar was included in my UINavigation that was colored differently to support the top nav bar. I separated them and now it's working as expected.

like image 53
Jake Lisby Avatar answered Nov 15 '22 00:11

Jake Lisby


I had the same problem solved it with setting the title of shown view controllers in their init function: https://stackoverflow.com/a/4417666/3647974.

like image 29
Jason Saruulo Avatar answered Nov 15 '22 00:11

Jason Saruulo