简体   繁体   English

从AppDelegate,Swift导航到TabBarController内部的特定View Controller

[英]Navigate to a specific View Controller inside a TabBarController from AppDelegate, Swift

I have a TabBarController with two tabs Cases & Settings 我有一个带有两个选项卡的TabBarController案例和设置

I would like to take the user to CaseSummaryTVC which is nested like this TabBarController > Cases (NavigationController, Storyboard Id = 'tvcNav' ) > CasesTVC (TableViewController) > CaseSummaryTVC (TableViewController, Storyboard Id = 'CaseSummaryTVC'). 我想将用户带到嵌套有这样的TabBarController> Cases(NavigationController,Storyboard Id ='tvcNav')> CasesTVC(TableViewController)> CaseSummaryTVC(TableViewController,Storyboard Id ='CaseSummaryTVC')的CaseSummaryTVC。

I am using the below code in AppDelegate, which takes me to the 'CaseSummaryTVC' but doesn't show the TabBar on the bottom . 我在AppDelegate中使用以下代码,该代码将我带到“ CaseSummaryTVC”,但未在底部显示TabBar

let mainStoryboard: UIStoryboard = UIStoryboard(name: "Main", bundle: nil)
        let navController = mainStoryboard.instantiateViewController(withIdentifier: "tvcNav") as! UINavigationController

        let caseSummaryTVC = mainStoryboard.instantiateViewController(withIdentifier: "CaseSummaryTVC") as! CaseSummaryTVC

navController.pushViewController(caseSummaryTVC, animated: true)


self.window?.rootViewController = navController
self.window?.makeKeyAndVisible()

It looks like you're setting your window's rootViewController to be 'navController', which doesn't seem to be wrapped in a UITabBarController. 看起来您要将窗口的rootViewController设置为“ navController”,似乎并未包装在UITabBarController中。

I'm not sure what your storyboard looks like, but it sounds like you have the view hierarchy setup correctly there. 我不确定您的情节提要是什么样子,但是听起来好像您已经正确设置了视图层次结构。

You could do one of the following: 您可以执行以下操作之一:

1) Remove the programmatic view controller instantiation and have the storyboard take care of setting the rootViewController to the UITabBarController. 1)删除程序化视图控制器实例,并让情节提要将rootViewController设置为UITabBarController。

2) Instantiate the UITabBarController programmatically like you have done here with the other view controllers, and make sure it's set up to have the navController as one of it's tabs. 2)像在此处使用其他视图控制器一样,以编程方式实例化UITabBarController,并确保将其设置为将navController作为其选项卡之一。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM