UITabBarItem 在应用程序启动时未激活
UITabBarItem not active on app start
我有 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
在应用程序启动时处于活动状态?
不在调用 viewDidLoad 期间尝试 tabBarItem = UITabBarItem,而是在创建 ViewController 时 - 在 init
我有 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
在应用程序启动时处于活动状态?
不在调用 viewDidLoad 期间尝试 tabBarItem = UITabBarItem,而是在创建 ViewController 时 - 在 init