Setting the default bookmark in UITabBar in quick

I'm almost done with the project and am developing the last few UI kinks. My app uses a tab bar for navigation and aesthetic purposes. I want the app to open in the last tab (User Profile) instead of the first. I know I can change the order of the tabs in Interface Builder, but the tab bar would look odd if the profile tab was the first and home tab elsewhere. How can I leave the profile tab as the fifth tab, but open the application in that tab by default?

+3


source to share


3 answers


Just set selectedIndex tabBarController. Something like that.



var freshLaunch = true
override func viewWillAppear(animated: Bool) {
     if freshLaunch == true {
         freshLaunch = false
         self.tabBarController.selectedIndex = 4 // 5th tab
     }
}

      

+7


source


There is a great way to do this right from the UI designer on the tab bar controller by clicking the ID inspector and set the User / STRONG> Runtime Attribute .

In this case, each index of the tab control is indexed as an array based on 0. So the leftmost is 0, the next to the right is 1, then 2, and so on.



So in my case, I wanted the "tasks" to be selected first, so you set the SelectedIndex to Number and to "1". Refer to my attached image.

enter image description here

+18


source


In the First items view manager write

tabBarController?.selectedIndex = 2//required value

      

+1


source







All Articles