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

Tejas Ardeshna
  • 4,343
  • 2
  • 20
  • 39
Jake Lisby
  • 494
  • 5
  • 21

3 Answers3

8

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.

Jake Lisby
  • 494
  • 5
  • 21
4

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.

Community
  • 1
  • 1
Jason Saruulo
  • 1,837
  • 4
  • 21
  • 21
1

Even I faced the same issue. I solved it by writing following code

let storyboard   = UIStoryboard.init(name: "Main", bundle: Bundle.main)
let vc1          = storyboard.instantiateViewController(withIdentifier: "ViewController") as! ViewController
vc1.tabBarItem   = ESTabBarItem.init(ExampleIrregularityBasicContentView(), title: "Home", image: UIImage(named: "home"), selectedImage: UIImage(named: "home_1"))

Hope it will help you

Mayur Rathod
  • 361
  • 3
  • 13