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;
}
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With