jjzjj

ios - swift 2 : How to Load UITabBarController after Showing LoginViewController

coder 2023-09-12 原文

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

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。

谁能帮帮我?提前致谢。

@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)


    }

最佳答案

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

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
    }

这是来自登录按钮操作:

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

只需将“TabBarController”作为 UITabBarController 的 Storyboard 中的标识提及即可。我创建了一个分别嵌入了 UINavigationController 和 UITabBarController 的 Viewcontroller 以及三个 UIViewController。

我希望它能帮助别人。谢谢。

关于ios - swift 2 : How to Load UITabBarController after Showing LoginViewController,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32562015/

有关ios - swift 2 : How to Load UITabBarController after Showing LoginViewController的更多相关文章

随机推荐