实例化视图控制器

实例化视图控制器

本文介绍了实例化视图控制器 Swift 3 标签栏控制器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何转到标签栏控制器?标签上有 2 个视图控制器,带有导航控制器,标签栏控制器上有一个导航控制器.

How can I segue to a tab bar controller? Theres 2 view controllers on tabs with navigation controllers and a navigation controller on the tab bar controller.

let storyboard = UIStoryboard(name: "PendingOverview", bundle: nil)
let vc = storyboard.instantiateViewController(withIdentifier: "PendingOverviewVC") as! PendingOverViewController
let nc = UINavigationController(rootViewController: vc)
self.present(nc, animated: false, completion: nil)

谢谢

推荐答案

Storyboard 中将 identifier 设置为 UITabbarController 然后使用 instantiateViewController 表示UITabbarController.

In Storyboard set identifier to UITabbarController and then using instantiateViewController present that UITabbarController.

let storyboard = UIStoryboard(name: "PendingOverview", bundle: nil)
let tabbarVC = storyboard.instantiateViewController(withIdentifier: "TabbarIdentifier") as! UITabbarController
if let vcs = tabbarVC.viewControllers,
   let nc = vcs.first as? UINavigationController,
   let pendingOverVC = nc.topViewController as? PendingOverViewController {

      pendingOverVC.pendingResult = pendingResult
}
self.present(tabbarVC, animated: false, completion: nil)

这篇关于实例化视图控制器 Swift 3 标签栏控制器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-11 05:02