简体   繁体   English

过渡到新的视图控制器

[英]Transitioning to a new view controller

So this piece of code is called after authenticating the users login details: 因此,在验证用户登录详细信息之后,将调用以下代码:

func completeLogin() {
        dispatch_async(dispatch_get_main_queue(), {
            let tabBarController = self.storyboard!.instantiateViewControllerWithIdentifier("PostLoginTabBarController") as! UITabBarController
            let tableViewController = self.storyboard!.instantiateViewControllerWithIdentifier("InformationTableViewController") as! InformationTableViewController
            let tableViewNavController = UINavigationController(rootViewController: tableViewController)
            tabBarController.viewControllers?.removeAll()
            tabBarController.viewControllers?.append(tableViewNavController)
            self.presentViewController(tabBarController, animated: true, completion: nil)
        })
    }

In my storyboard: 在我的故事板中:

在此处输入图片说明

I have the PostLoginTabBarController that has a relationship with 2 other ViewControllers 我有PostLoginTabBarController与其他2个ViewControllers有关系

My question is: 我的问题是:

Is there a better way than removing all the View Controllers that the PostLoginTabBarController has and then adding the new instantiated ones in the completeLogin() method? 有没有比删除PostLoginTabBarController具有的所有View Controllers ,然后在completeLogin()方法中添加新的实例化View Controllers更好的方法? The reason I am doing this is because if I sever the relationship between the PostLoginTabBarController when the PostLoginTabBarController is presented it shows a black screen, but if I don't sever the relationship then it is fine. 我这样做的原因是因为如果我断绝关系PostLoginTabBarControllerPostLoginTabBarController呈现它显示黑屏,但如果我不断绝关系,然后它是好的。

Here is an example when I sever the relationship: 这是我断开关系时的一个示例:

在此处输入图片说明

And when I don't: 当我不这样做时:

在此处输入图片说明

Have you tried using setViewControllers(_ viewControllers: [UIViewController]?, animated animated: Bool) instead of 您是否尝试过使用setViewControllers(_ viewControllers: [UIViewController]?, animated animated: Bool)代替

tabBarController.viewControllers?.removeAll()
tabBarController.viewControllers?.append(tableViewNavController)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 过渡到新的视图控制器时如何更新状态栏样式? - How to update the status bar style when transitioning to a new view controller? 问题过渡到根视图控制器 - Problem transitioning to root view controller 页面视图控制器未按照其编码的样式转换 - page view controller not transitioning in the style it is coded to 身份验证完成后过渡到新视图 - transitioning to a new view after authentication is complete 查看过渡 - View Transitioning “呈现的视图控制器始终全屏显示”不适用于iOS 7自定义过渡吗? - “presented view controller always full screen” not true for iOS 7 custom transitioning? 使用按钮从一个视图控制器过渡到另一个 - transitioning from one view controller to another using a button Swift:通过TabBar和导航控制器以编程方式从一个视图过渡到另一个视图 - Swift: Programmatically transitioning from 1 view to another via a TabBar and Navigation Controller 将数据从一个视图控制器传递到另一个不转换 - Pass data from one view controller to another without transitioning SwiftUI 奇怪的动画通过 NavigationLink 过渡到新视图? - SwiftUI Strange Animation Transitioning via NavigationLink to a new View?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM