[英]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. 我这样做的原因是因为如果我断绝关系
PostLoginTabBarController
当PostLoginTabBarController
呈现它显示黑屏,但如果我不断绝关系,然后它是好的。
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.