简体   繁体   中英

Segue out of a UINavigationController stack to UITabBarController

I have Login.storyboard :

在此处输入图片说明

The Login View Controller has a Segue to a Storyboard Reference and the storyboard main.storyboard :

在此处输入图片说明

My LoginViewController class code has a TouchUpInside action handler that programmatically calls the segue to main.storyboard :

@IBAction func btnLoginTouchUpInside(sender: UIButton) {
        let params = AuthLoginParams(Username: txtFieldUsername.text!, Password: txtFieldPassword.text!)

        AuthLoginRequest.FetchUser(params) { (userModel) -> Void in
            if(userModel.IsAuthorized){
                self.performSegueWithIdentifier("mainStoryboardSegue", sender: nil)
            }else{

            }
        }
    }

Now let's look at main.storyboard

在此处输入图片说明

So from Login.storyboard -> successful login segue -> Main.storyboard I am trying to segue "out" of a UINavigationController stack and start new/fresh with a UITabBarController . Here is a screen shot if I start my app with main.storyboard and skip the Login.storyboard : 在此处输入图片说明

But if I start my app with Login.storyboard and the try using my segue to Stoyboard Reference main.storyboard with self.performSegueWithIdentifier("mainStoryboardSegue", sender: nil)

I am still in the Login process UINavBarController stack which I do not want:

在此处输入图片说明

Thanks to @Paulw11's tip in my question comments, he stated that I cannot do what I am trying to with a simple segue, I have to programmtically change the rootViewController and this is the code I came up with, including a transition amimation and all seems to be working nicely:

 let mainStoryboard: UIStoryboard = UIStoryboard(name: "Main", bundle: nil)
 let viewController = mainStoryboard.instantiateViewControllerWithIdentifier("dashboardTabBarController") as! DashboardTabBarController

 UIView.transitionWithView(self.view.window!, duration: 0.5, options: UIViewAnimationOptions.TransitionCrossDissolve, animations: {
                    UIApplication.sharedApplication().keyWindow?.rootViewController = viewController;
                    }, completion: nil)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM