-5

I am trying to present a certain tab on a tab view controller from a view controller when the user clicks login and is logged in but only if they are logged in so this is why I am doing this programmatically. Would I make a segue with an identity or use something like self.present?

Hasya
  • 9,792
  • 4
  • 31
  • 46
  • 2
    Kindly update your post with code that you have done to achieve this. – Hasya Dec 01 '16 at 15:57
  • see [here](https://stackoverflow.com/questions/19962276/best-practices-for-storyboard-login-screen-handling-clearing-of-data-upon-logou). You will find various answers in Swift & Objective-C with good discussions in the comments. It is generally recommended that you search for other questions and link them in your own question and explain why they didn't answer your question – mfaani Dec 01 '16 at 16:00

1 Answers1

0

Provided your rootController is the UITabBarController, you can do this as follows.

    @IBAction func loginButtonPressed(_ sender: Any) {
    let rootController = (window?.rootViewController)!
    let tabBarController = rootController as! UITabBarController
    tabBarController.selectedIndex = 2

    }

Select the index of the tab bar you would like displayed and it will display. In this example I have assumed it is 2.

gwinyai
  • 2,560
  • 2
  • 15
  • 17
  • else{ //prepare(for: <#T##UIStoryboardSegue#>, sender: <#T##Any?#>) let vc = self.tabBarController?.storyboard?.instantiateViewController(withIdentifier: "HomeViewController") self.tabBarController?.present(vc!, animated: true, completion: nil) //self.present(vc!, animated: true, completion: nil) – Hunter Cole Dec 01 '16 at 22:55