title: Loading a new viewController on the same tab bar item not working
body: <p>So I am having a problem loading a new view controller on the same tab bar item. I have a tab bar controller as my root controller and 4 tabs on the tab bar. One of which is the account tab, when the user is logged in he would need to see an overview of his account details but when there is no user there needs to be a sign-in / login page on that tab bar item. For the moment I have a custom tab bar class for my tabbarcontroller with a function that I thought was the solution but nothing happens. I have put a breakpoint in the view controller that needs to loaded (the user detail page) and it comes in the ViewDidLoad so it loads but it doesn't appear on the screen. </p>
  
  <p>Hope I can finally solve this problem! </p>
  
  <p>Kind regards
  B.</p>
  
  <p>this is my custom tab bar controller class:</p>
  
  <pre><code>import UIKit
  
  class TabBarViewController: UITabBarController, UITabBarControllerDelegate {
      var window: UIWindow?
      override func viewDidLoad() {
          super.viewDidLoad()
          self.delegate = self
  
      }
  
  
      func tabBarController(_ tabBarController: UITabBarController,
                            shouldSelect viewController: UIViewController) -&gt; Bool{
          let frame = UIScreen.main.bounds
          window = UIWindow(frame: frame)
          let index = tabBarController.viewControllers?.firstIndex(of: viewController)
          if index == 3{ // Index of Account tab
              let mainStoryBoard: UIStoryboard = UIStoryboard(name: "Main", bundle: nil)
              let loginVC = mainStoryBoard.instantiateViewController(withIdentifier: "MessagesViewController") as! MessagesViewController
              window?.rootViewController = loginVC
              window?.makeKeyAndVisible()
          }
          return true// you decide
      }
  }
  
  
  </code></pre>