UITabbar 项目不显示,直到单击升级到 Xcode 7
Posted
技术标签:
【中文标题】UITabbar 项目不显示,直到单击升级到 Xcode 7【英文标题】:UITabbar items not showing until click following upgrade to Xcode 7 【发布时间】:2015-09-21 14:49:52 【问题描述】:我有一个UITabBar
,在我升级到 Xcode 7 之前它运行良好,但现在我无法弄清楚我的生活会发生什么。我尝试了几种解决方案,包括为我创建的每个选项卡设置imageWithRenderingMode
,尝试更改UITabBar
的背景颜色以查看这些项目是否只是白色,并将图标本身更新为新版本。我默认选择的选项卡显示得很好,然后当我选择另一个选项卡时,文本显示,但没有图像。 (当移动到另一个选项卡时,文本也会保留并更改为默认灰色。)
我附上了我所看到的截图,这是我目前实现标签栏的方式。
创建标签栏的功能:
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];
在每个视图中创建标签的代码:
- (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;
【问题讨论】:
【参考方案1】:经过大量试验和错误后,我发现问题是由于导航控制器造成的,并且我的标签栏包含在我的 UINavigation 中,它的颜色不同以支持顶部导航栏。我将它们分开,现在它按预期工作。
【讨论】:
【参考方案2】:通过在其初始化函数中设置显示的视图控制器的标题,我解决了同样的问题:https://***.com/a/4417666/3647974。
【讨论】:
【参考方案3】:即使我也面临同样的问题。 我通过编写以下代码解决了它
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"))
希望对你有帮助
【讨论】:
以上是关于UITabbar 项目不显示,直到单击升级到 Xcode 7的主要内容,如果未能解决你的问题,请参考以下文章