我有UITabBar控制器
let tabBarController = UITabBarController()
tabBarController.viewControllers = [todayViewController, forecastViewController]
window.rootViewController = tabBarController
window.makeKeyAndVisible()
tabBarController.selectedIndex = 0
在todayViewController
内:
tabBarItem = UITabBarItem(title: "Today", image: #imageLiteral(resourceName: "TodayTabBarItem"), selectedImage: #imageLiteral(resourceName: "SunTabBarItemSelected"))
在forecastViewController
内:
tabBarItem = UITabBarItem(title: "Forecast", image: #imageLiteral(resourceName: "ForecastTabBarItem"), selectedImage: #imageLiteral(resourceName: "ForecastTabBarItemSelected"))
当我启动第一个视图控制器的应用UITabBarItem
时,它处于非活动状态。当我点击它或另一个时,它变为活动状态(突出显示的文本和右图)
如何在应用启动时激活UITabBarItem
?
答案 0 :(得分:1)
在调用viewDidLoad期间尝试tabBarItem = UITabBarItem,但在创建ViewContrller时 - 在init