在标签栏导航 App 中跳过场景代表的登录屏幕

Skip login screen from scene delegate in tabbed bar navigation App

我试图在用户登录时跳过登录屏幕并直接转到 MainViewController。但是问题是我在登录和主屏幕之间有一个选项卡栏控制器和导航控制器 vc.经过大量搜索,我写了下面的代码

 func showMainViewController() {
        let storyboard = UIStoryboard(name: "Main", bundle: nil)
        let mainViewController: MainViewController = storyboard.instantiateViewController(withIdentifier: "MainViewController") as! MainViewController


        let navigationController = UINavigationController(rootViewController: mainViewController)

        //It removes all view controllers from the navigation controller then sets the new root view controller and it pops.
        window?.rootViewController = navigationController

//        //Navigation bar is hidden
//        navigationController.isNavigationBarHidden = true
    }

但是它无法显示标签栏视图控制器。任何帮助表示赞赏。

试试这个

func showMainViewController() {
        let storyboard = UIStoryboard(name: "Main", bundle: nil)
        let mainViewController: MainViewController =      storyboard.instantiateViewController(withIdentifier: "TabBar") 

        window?.rootViewController = mainViewController
        window?.makeKeyAndVisible()
    }

你应该实例化 TabBar no main viewController。因为在中间实例化是如果第一个索引或设置选定的索引