如何在 Swift 编程中获得基于导航的模板功能

2023-05-17移动开发问题
0

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

问题描述

限时送ChatGPT账号..

我的项目需要一个导航控制器,并且我的应用程序最初有一个社交登录.验证身份验证后,用户将被推送到另一个视图,在该视图中我会显示一个具有 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 编程中做到这一点.我已经将我的视图控制器嵌入到导航控制器中,一旦身份验证成功,我如何将用户推送到标签栏视图?标签栏也应该有导航.

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

对 Tab Bar Controller 执行相同操作,分配 Storyboard 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

当用户登录我们时,再次将根视图更改为 Login Nav:

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 编程中获得基于导航的模板功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

The End

相关推荐

硬件音量按钮更改应用程序音量
Hardware Volume buttons change in app volume(硬件音量按钮更改应用程序音量)...
2024-08-12 移动开发问题
10

恢复游戏 cocos2d
Resume game cocos2d(恢复游戏 cocos2d)...
2024-08-12 移动开发问题
6

Cocos2D + 仅禁用 Retina iPad 图形
Cocos2D + Disabling only Retina iPad Graphics(Cocos2D + 仅禁用 Retina iPad 图形)...
2024-08-12 移动开发问题
10

[ios.cocos2d+box2d]如何禁用自动旋转?
[ios.cocos2d+box2d]how to disable auto-rotation?([ios.cocos2d+box2d]如何禁用自动旋转?)...
2024-08-12 移动开发问题
7

从 Documents 目录存储和读取文件 iOS 5
Storing and reading files from Documents directory iOS 5(从 Documents 目录存储和读取文件 iOS 5)...
2024-08-12 移动开发问题
9

如何在 cocos2d 环境之外实现 cocos2d 游戏的虚拟摇杆?
How can I implement a virtual joystick for a cocos2d game outside the cocos2d environment?(如何在 cocos2d 环境之外实现 cocos2d 游戏的虚拟摇杆?)...
2024-08-12 移动开发问题
13