我有一个 UITabBar
,它在我升级到 Xcode 7 之前运行良好,但现在我无法弄清楚我的生活发生了什么。我尝试了几种解决方案,包括为我创建的每个选项卡设置 imageWithRenderingMode
,尝试更改 UITabBar
的背景颜色以查看项目是否只是白色,以及将图标本身更新为新版本。我默认选择的选项卡显示得很好,然后当我选择另一个选项卡时,显示文本,但没有图像。 (移动到另一个选项卡时,文本仍然存在并更改为默认灰色。)
我附上了我所看到的屏幕截图,这是我目前实现标签栏的方式。
创建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];
}
在每个 View 中编写代码以创建选项卡:
- (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;
}
最佳答案
经过大量试验和错误后,我发现问题出在导航 Controller 上,并且我的标签栏包含在我的 UINavigation 中,它的颜色不同以支持顶部导航栏。我将它们分开,现在它按预期工作。
关于ios - UITabbar 项目在升级到 Xcode 7 后单击后才会显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32698274/