简体   繁体   中英

How do I change the default tab bar item in iOS Swift?

override func viewDidAppear(animated: Bool) {
    super.viewDidAppear(animated)
    println("TabBar viewDidAppear")
    self.checkForNewKey()
    if freshLaunch == true {
        freshLaunch = false
        self.tabBar.selectedItem = tabBar.items![2] as? UITabBarItem
    }
}

I did this...but the entire app crashes (not sure why). I have 5 items in my tab bar.

use self.tabBarController.selectedIndex = 2

instead of self.tabBar

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM