How to get navigation based template functionality in Swift programming

*爱你&永不变心* 提交于 2019-11-26 11:33:23

问题


I need a navigation controller through out my project and my application has a social login initially. Once the authentication is verified user will be pushed to another view, where I display a tabbarcontroller having 2 tabs.

I don\'t know how to do this in Swift programming. I have embed my viewcontroller in Navigation controller, from here once the authentication is successful how do I push user to tabbar view? Tabbar should also have navigation.


回答1:


I would like to replicate your idea into what I usually do in the following example.

This is how my storyboard looks like:

As you can see login/signup and Tab bar is not connected with any kind of Segue.

Here Sign in Navigation controller is setup of Initial Controller.

Assign This Navigation Controller an Storyboard ID(e.g.LoginNavigation):

Do the same with Tab Bar Controller, assign Storyboard ID(e.g. HomeTabBar)

Now, you just have to shuffle Root View Controller of the app between Login Nav and Tab Bar.

So if user successfully logs in, changes the application's root view to HomeTabBar using following code:

let storyboard: UIStoryboard = UIStoryboard(name: "Main", bundle: nil)
let home: UITabBarController = storyboard.instantiateViewControllerWithIdentifier("HomeTabBar") as! UITabBarController
appDelegate.window?.rootViewController = home

And when user logs our, again change the root view to Login Nav:

let mainStoryboard: UIStoryboard = UIStoryboard(name: "Main", bundle: nil)
let entryPoint:UIViewController = mainStoryboard.instantiateViewControllerWithIdentifier("LoginNavigation")
appDelegate.window?.rootViewController = entryPoint

The appDelegate is defined in my constants.swift file :

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


来源:https://stackoverflow.com/questions/39159444/how-to-get-navigation-based-template-functionality-in-swift-programming

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!