Ios 选项卡栏不显示在导航控制器内部的视图控制器上
当我以编程方式打开新的视图控制器时,遇到了这个问题Ios 选项卡栏不显示在导航控制器内部的视图控制器上,ios,swift,uinavigationcontroller,uitabbarcontroller,uistoryboard,Ios,Swift,Uinavigationcontroller,Uitabbarcontroller,Uistoryboard,当我以编程方式打开新的视图控制器时,遇到了这个问题 let controller = self.storyboard?.instantiateViewController(withIdentifier: "overViewScreen") as! OverviewViewController controller.user = self.userObject let navigationController = UINavigationController(rootViewController:
let controller = self.storyboard?.instantiateViewController(withIdentifier: "overViewScreen") as! OverviewViewController
controller.user = self.userObject
let navigationController = UINavigationController(rootViewController: controller)
self.present(navigationController, animated: true, completion: nil)
我的项目结构:
在我的故事板上,选项卡栏显示在视图控制器上(表在右侧),但当我运行应用程序时,它看起来如下所示:
我希望你们能帮助我!
谢谢。您正在演示不带选项卡栏控制器的NavigationController。您需要呈现TabBarController 提供您的TabBarController标识符并实例化它们,就像您对控制器所做的一样 注释中的代码:
let tabVC = UIStoryboard(name: "NameOfYourStoryboard", bundle: Bundle.main).instantiateInitialViewController() as! UITabBarController
let navVc = tabVC.viewControllers.first as! UINavigationController
let vc = navVc.viewControllers.first as! OverviewViewController
vc.incorrectAuthorization = SettingsAuthorizationMethod.fingerprint
vc.user = self.userObject
present(navController, animated: true, completion: nil)
好的,我设法这样修复了它:
let vc = self.storyboard?.instantiateViewController(withIdentifier: "TabBarController") as! TabBarController
vc.user = self.userObject
let nvc = UINavigationController(rootViewController: vc)
self.present(nvc, animated: true, completion: nil)
我创建了一个单独的控制器类“TabBarController”,并向该类添加了一个属性“user”。在我的“概览控制器”中,我可以获得如下属性:
let tabBar: TabBarController = tabBarController as! TabBarController
user = tabBar.user
谢谢你的帮助 你是说像这样的事吗?让tabBarController=self.storyboard?.instanceeviewcontroller(带有标识符:“tabBarController”)self.present(tabBarController!,动画:true,完成:nil)或类似的内容:让tabVC=UIStoryboard(名称:“NameOfYourStoryboard”,bundle:bundle.main)!UITabBarController让navVc=tabVC.viewControllers.first作为!UINavigationController让vc=navVc.viewControllers.first as!LoginViewController vc.incorrectAuthorization=SettingsAuthorizationMethod.fingerprint vc.user=self.userObject present(navController,动画:true,完成:nil),所以现在我有了:let tabBarController=self.storyboard?.InstanceInitialViewController()as!UITabBarController让navVc=tabBarController.childViewControllers.first as!UINavigationController让vc=navVc.childViewControllers.first as!OverviewController vc.user=self.userObject self.present(navVc,动画:true,完成:nil)。错误:无法将LoginViewController强制转换为UITabbarController LoginViewController是我的类名,请将其更改为您的。