我有Uitabar控制器

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

最佳答案

不是在调用viewDidLoad期间,而是在init中创建ViewContrller时,尝试tabBarItem=UITabBarItem

关于ios - UITabBarItem在应用启动时未激活,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/50603852/

10-11 07:55