如何在Swift编程中获得基于导航的模板功能 [英] How to get navigation based template functionality in Swift programming

查看:113
本文介绍了如何在Swift编程中获得基于导航的模板功能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要一个导航控制器来完成我的项目,我的应用程序最初有一个社交登录。验证身份验证后,用户将被推送到另一个视图,在那里我显示一个带有2个选项卡的tabbarcontroller。

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.

我不知道如何在Swift编程中执行此操作。我已经将我的viewcontroller嵌入到导航控制器中,一旦验证成功,我如何将用户推送到tabbar视图? Tabbar也应该有导航。

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.

推荐答案

我想将你的想法复制到我通常在下面的例子中做的事情。

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

这就是我的故事板的样子:

This is how my storyboard looks like:

正如您所见,登录/注册和标签栏与任何类型的Segue都没有关联。

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.

为此导航控制器分配故事板ID(例如 LoginNavigation ):

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

对标签栏控制器执行相同操作,指定故事板ID(例如 HomeTabBar

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

现在,您只需要在Login Nav和Tab Bar之间随机播放应用程序的Root View Controller。

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

因此,如果用户成功登录,请使用以下代码将应用程序的根视图更改为 HomeTabBar

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

appDelegate 在我的 constants.swift 文件中定义:

The appDelegate is defined in my constants.swift file :

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

这篇关于如何在Swift编程中获得基于导航的模板功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆