Yuv*_*j.M 2 uitabbarcontroller uinavigationcontroller ios swift swift2
是Swift和Storyboard的新手.最初我必须显示登录页面,并从登录页面显示到UITabBarController.一旦用户记住登录详细信息,我必须检查AppDelegate中的登录详细信息,如果用户已经登录,则直接显示UITabBarController.我已经提到了一些SOF问题,但是没有得到结果.
我设计了嵌入了UINavigationController的LoginViewController.我有一个带有2个viewcontrollers的UITabBarController.我将LoginViewController设置为Storyboard中的inititialViewController.因此loginview首次显示.但是,我不知道如何从登录屏幕推送UITabBarController(登录按钮操作).此外,我不知道如何检查和加载登录和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)
}
Run Code Online (Sandbox Code Playgroud)
谢谢你的答案.我解决了这个问题,这是我的代码.
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
}
Run Code Online (Sandbox Code Playgroud)
这是来自登录按钮操作:
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
Run Code Online (Sandbox Code Playgroud)
只需在故事板中为UITabBarController提及"TabBarController"作为Identity.我创建了一个嵌入了UINavigationController和UITabBarController的ViewController,它们分别带有三个UIViewControllers.
我希望它会帮助别人.谢谢.
| 归档时间: |
|
| 查看次数: |
3479 次 |
| 最近记录: |