Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
249 views
in Technique[技术] by (71.8m points)

ios - How to get navigation based template functionality in Swift programming

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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

This is how my storyboard looks like:

enter image description here

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

Login NavigationController

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

TabBarController

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

56.9k users

...