Soy nuevo en Swift y Storyboard. Al principio tengo que mostrar la página de inicio de session y desde la página de inicio de session a UITabBarController. Una vez que el usuario recordó los detalles de inicio de session, debo verificar los detalles de inicio de session en AppDelegate y mostrar UITabBarController directamente si el usuario ya inició session. He remitido algunas preguntas de SOF, pero no obtengo el resultado.
Diseñé el LoginViewController embedded con UINavigationController. Y tengo un UITabBarController con 2 viewcontrollers. Configuré el LoginViewController como un inititialViewController en Storyboard. Entonces, la vista de inicio de session se muestra por primera vez. Pero, no sé cómo presionar UITabBarController desde la pantalla de inicio de session (Acción del button de inicio de session). Además, no sé cómo verificar y cargar el inicio de session y la barra de tabs
respectivamente desde appDelegate.
¿Alguien puede ayudarme por favor? Gracias por adelantado.
@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) }
Gracias por las respuestas. Resolví el problema y aquí está mi código.
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 }
Esto es de la acción del button de inicio de session:
let storyboard: UIStoryboard = UIStoryboard(name:"Main", bundle: NSBundle.mainBundle()) let tabBarController: UITabBarController = storyboard.instantiateViewControllerWithIdentifier("TabBarController") as! UITabBarController let appDelegate = UIApplication.shanetworkingApplication().delegate as! AppDelegate appDelegate.window!.rootViewController = tabBarController
Solo menciona el "TabBarController" como Identity in Storyboard para el UITabBarController. He creado un Viewcontroller embedded con UINavigationController y UITabBarController con tres UIViewControllers por separado.
Espero que ayude a otra persona. Gracias.
Por favor, consulte la image
su guión gráfico debe ser similar a la siguiente.
Luego, proporcione el identificador Storyboard Segue
que lo UITabbarController
a UITabbarController
desde LoginViewController
.
Luego paste
siguiente código desde donde desea navegar.
@IBAction func btnLogin_Click(sender: AnyObject) { self.performSegueWithIdentifier("LoginToTabBar", sender: self) //LoginToTabBar is identifier which you settled out in storyboard segue. }