当我以编程方式打开新的View Controller时,我遇到了这个问题。
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)
我的项目结构: storyboard
在我的故事板上,标签栏显示在View Controller上(右边的表格),但是当我运行应用程序时,它看起来像这样: enter image description here
我希望你们能帮助我! 谢谢。
答案 0 :(得分:0)
您正在展示没有标签栏控制器的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)
答案 1 :(得分:0)
好的,我设法解决了这个问题:
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"到这堂课。在我的" OverViewController"我可以按如下方式获得该物业:
let tabBar: TabBarController = tabBarController as! TabBarController
user = tabBar.user
感谢您的帮助!