如何使用标签栏控制器呈现导航控制器

How to present navigation controller with tab bar controller

我有导航控制器和标签栏控制器。 TBC 嵌入在 NC 中。当我从另一个 VC 显示 VC 时,我在那里只看到 NC 而不是 TBC。我希望他们都被展示。我该怎么办?

这是我的代码:

let mainAreaVC = self.storyboard?.instantiateViewController(withIdentifier: "MainAreaVC") as! MainAreaVC
let mainAreaVCe = UINavigationController(rootViewController: mainAreaVC)
self.present(mainAreaVCe, animated: true, completion: nil)

如果你想用 NavigationControllerTabBarcontroller 显示 MainAreaVC,那么你需要显示 UITabBarController 而不是 MainAreaVC。所以在故事板中为你的 TabBarController 设置 Storyboard Id 类似 TabbarVC 或任何你想要的东西然后使用它机智 instantiateViewController 得到 UITabBarController.

let tabbarVC = self.storyboard?.instantiateViewController(withIdentifier: "TabbarVC") as! UITabBarController
self.present(tabbarVC, animated: true, completion: nil)