Swift 2:如何在显示LoginViewController后加载UITabBarController [英] Swift 2: How to Load UITabBarController after Showing LoginViewController

查看:77
本文介绍了Swift 2:如何在显示LoginViewController后加载UITabBarController的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Swift和Storyboard的新手.最初,我必须显示登录页面,然后从登录页面显示UITabBarController.一旦用户记住了登录详细信息,我就必须在AppDelegate中检查登录详细信息,如果用户已经登录,则必须直接显示UITabBarController.我已经提到了一些SOF问题,但是没有得到结果.

Am new to Swift and Storyboard. At initially I have to show the login page and from the login page to UITabBarController. Once the user remembered the login details I have to check the login details in the AppDelegate and show the UITabBarController directly if the user already logged in. I have referred some SOF questions but, am not getting the result.

我设计了嵌入了以下内容的LoginViewController UINavigationController.我有一个UITabBarController和2 视图控制器.我将LoginViewController设置为 情节提要中的inititialViewController.因此,loginview显示在 第一次.但是,我不知道如何推送UITabBarController 从登录屏幕上(登录按钮操作).我也不知道该怎么办 检查并加载登录名和标签栏

I designed the LoginViewController embedded with UINavigationController. And I have one UITabBarController with 2 viewcontrollers. I set the LoginViewController as a inititialViewController in Storyboard. So the loginview is showing at very first time. But, I don't know how to push the UITabBarController from the login screen (Login Button Action). Also I don't know how to check and load the login and tabbar

分别来自appDelegate.

respectively from appDelegate.

有人可以帮助我吗?提前致谢.

Can anyone please help me? Thanks in advance.

@IBAction func loginButtonAction (button : UIButton) {

        if isRemeberLogin == true {
            let loginClass = LoginModelClass(userNameValue: (usernameTF?.text)!, passwordValue: (passwordTF?.text)!)
            print("Remembering Login Details: \(loginClass.userName, loginClass.passWord)")

        }

        let homeVC = self.storyboard?.instantiateViewControllerWithIdentifier("HomeViewController") as! HomeViewController
        let collectionVC = self.storyboard?.instantiateViewControllerWithIdentifier("ItemsCollectionViewController") as! ItemsCollectionViewController


        //self.navigationController?.pushViewController(homeVC, animated: true)

        let tabBarController = self.storyboard?.instantiateViewControllerWithIdentifier("TabBarController") as! UITabBarController

        print("TABBAR \(tabBarController)")
        let viewControllersArray = [homeVC, collectionVC];
       // tabBarController?.viewControllers = viewControllersArray

        self.navigationController?.pushViewController(tabBarController, animated: true)


    }

推荐答案

谢谢您的回答.我解决了这个问题,这是我的代码.

Thank you for the answers. I resolved the issue and here is my code.

func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
        // Override point for customization after application launch

        let username = NSUserDefaults.standardUserDefaults().objectForKey("Username")
        print(username)

        let storyBoard: UIStoryboard = UIStoryboard(name:"Main", bundle: NSBundle.mainBundle())

        if username?.length > 0 {
            print("User already logged In")
            let tabBarController: UITabBarController = storyBoard.instantiateViewControllerWithIdentifier("TabBarController") as! UITabBarController
            self.window?.makeKeyAndVisible()
            self.window?.rootViewController = tabBarController
        } else {
            print("New User")
            let loginViewController: ViewController = storyBoard.instantiateViewControllerWithIdentifier("ViewController") as! ViewController
            self.window?.makeKeyAndVisible()
            self.window?.rootViewController = loginViewController
        }


        return true
    }

这是从登录"按钮操作获得的:

This is from Login Button Action:

let storyboard: UIStoryboard = UIStoryboard(name:"Main", bundle: NSBundle.mainBundle())
        let tabBarController: UITabBarController = storyboard.instantiateViewControllerWithIdentifier("TabBarController") as! UITabBarController

        let appDelegate = UIApplication.sharedApplication().delegate as! AppDelegate
        appDelegate.window!.rootViewController = tabBarController

只需在UITabBarController的情节提要中提及"TabBarController"作为身份.我创建了一个嵌入了UINavigationController和UITabBarController的Viewcontroller,分别带有三个UIViewControllers.

Just mention the "TabBarController" as Identity in Storyboard for the UITabBarController. I have created a Viewcontroller embedded with UINavigationController and UITabBarController with three UIViewControllers separately.

我希望它会对其他人有所帮助.谢谢.

I hope it will help someone else. Thanks.

这篇关于Swift 2:如何在显示LoginViewController后加载UITabBarController的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆