how to close a tabbar swift

728 Views Asked by At

I have a login view controller which on a correct login will open a tabbar controller with the following method:

self.dismissViewControllerAnimated(true, completion: { self.loadHomeScreen()})

func loadHomeScreen()
    {
        emailField.text = ""
        passwordField.text = ""

        self.presentViewController(UIStoryboard.tabbarController()!, animated: true, completion: nil)
    }


private extension UIStoryboard {
        class func mainStoryboard() -> UIStoryboard { return UIStoryboard(name: "Main", bundle: NSBundle.mainBundle()) }

        class func tabbarController() -> UITabBarController? {
            return mainStoryboard().instantiateViewControllerWithIdentifier("TabbarControllerID") as? UITabBarController
        }
    }

I think my login view controller is still in the background? I have a logout button as the rightbarbutton item on each navbar in my tabgroup. I want to be able to close the tabbar on this button press. How can I achieve this. I can't find any examples. Would I be using a pop command?

UPDATE:

@IBAction func tryLogout(sender: UIBarButtonItem) {
        self.dismissViewControllerAnimated(true, completion: nil)
        let storyboard = UIStoryboard(name: "main", bundle: nil)
        let vc = storyboard.instantiateViewControllerWithIdentifier("login") as! UIViewController
        self.presentViewController(vc, animated: true, completion: nil)
    }
0

There are 0 best solutions below