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

标签 ios swift uinavigationcontroller uitabbarcontroller swift2

我是 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 - 将存储的struct数据修改为其他结构

ios - 远程通知不会在后台启动应用程序

ios - IBM MobileFirst 7.0 - libstdc++.6.dylib 上的 Xcode 10.1/iOS 12 问题

ios - 键盘卡在 ios 13 模拟器中

ios - 导航 Controller 为零,但嵌入在 View Controller 中

ios - 如何防止大标题折叠

ios - 由于 http post 请求上的 '&' 字符,字符串参数被分割

json - 如何在 swift 4.2 中将 JSON 转换为 Codable?

ios - 使用 Dispatch Group 时异步函数需要很长时间

ios - UINavigationBar + UIToolBar UIAppearance 以及应用程序某些部分的半透明 barStyle?