我如何 return 到 Main.storyboard 其中包含来自另一个 Storyboard 的 TabBarController

How can i return to Main.storyboard which contains a TabBarController from another Storyboard

我有两个故事板,一个包含应用程序的所有内容,另一个包含我的应用程序的 "onboarding"/教程。

本教程完成后,我想导航回我原来的视图控制器。

这是我导航到另一个故事板的代码:

let defaults = UserDefaults.standard
if defaults.bool(forKey: "firstOpened") {
    print("First VC launched")
}else{
    var vc: UIViewController
    let goTo = UIStoryboard(name: "Onboarding", bundle: nil).instantiateViewController(withIdentifier: "notificationStoryboard") as! FirstOnboardingViewController
    self.present(goTo, animated: true, completion: nil)    
}

有了这个,它就可以工作了,除了 TabBarController 没有显示,而且没有按照我想要的方式工作。

这是我导航回 Main.Storyboard 的代码:

@objc func handleSecondPush() {
    //registerForRemoteNotifications() 
    UserDefaults.standard.set(true, forKey: "firstOpened")
    let goTo = UIStoryboard(name: "Main", bundle: nil).instantiateViewController(withIdentifier: "pushToFeedVC") 
    self.present(goTo, animated: true, completion: nil)
    //self.performSegue(withIdentifier: "goToLink", sender: nil)   
}

我也在另一个 Storyboard 中尝试过,但是这个按钮不会改变视图:

let storyboard = UIStoryboard(name: "Main", bundle: nil)
let controller = storyboard.instantiateViewController(withIdentifier: "MainTabBarController") as! UITabBarController
print(controller)
self.window?.rootViewController = controller
self.window?.makeKeyAndVisible()
if let tabBarVc = self.window?.rootViewController as? UITabBarController {
    tabBarVc.selectedIndex = 1
}

简短的问题:所以我的问题是,我如何导航回 main.storyboard,它将包含选定索引为 1 的 TabBarController,从不包含导航控制器或 TabBarController 的故事板?

当您展示入职信息时,您应该 return 返回带有

的选项卡
self.dismiss(animated:true,completion:nil)

对于复杂的演示文稿,您可以这样做以便于重新返回

let vc = storyboard.instantiateViewController(withIdentifier: "MainTabBarController") as! UITabBarController  
(UIApplication.shared.delegate as! AppDelegate).window!.rootViewController = vc

更好的是

  let goTo = UIStoryboard(name: "Onboarding", bundle: nil).instantiateViewController(withIdentifier: "notificationStoryboard") as! FirstOnboardingViewController 
  let nav = UINavigationController(rootViewController:goTo)
  nav.isNavigationBarHidden = true
  self.present(nav, animated: true, completion: nil)

the flow inside the onbarding should be with pushViewController

然后在最后一次入职时解雇 vc

  if let tab =  (UIApplication.shared.delegate as! AppDelegate).window?.rootViewController as? UITabBarController {
     tab.dismiss(animated:true,completion:nil)
  }