Redirect to other controller when click Tab Bar item
<p>I have a Tab Bar that connect to 2 <code>TableView</code>, said that <code>Tab1</code> go to <code>Test1TableController</code>, and <code>Tab2</code> go to <code>Test2TableController</code>, what I want when I click <code>Tab2</code>, it check session first and If the session doesn't exists it will go to other controller before go to <code>Test2TableController</code> but my code can't do that</p>

<p>This is my code:</p>

<pre><code>func tabBarController(tabBarController: UITabBarController, didSelectViewController viewController: UIViewController) {

    if(self.tabBarController?.selectedIndex == 1) {
        let prefs:NSUserDefaults = NSUserDefaults.standardUserDefaults()
        let isLoggedIn:Int = prefs.integerForKey("ISLOGGEDIN") as Int
        if (isLoggedIn != 1) {
            let storyboard = UIStoryboard(name: "Main", bundle: NSBundle.mainBundle())
            let destination = storyboard.instantiateViewControllerWithIdentifier("LoginController") as! LoginController
            navigationController?.pushViewController(destination, animated: true)
        }
    }

}
</code></pre>

<p>please help me how to do that ? I have search for several web but can't find like what I want.</p>

<p>Just give me some hint. Thanks</p>