如何从另一个Storyboard返回包含TabBarController的Main.storyboard

问题描述 投票:0回答:1

我有两个故事板,一个包含应用程序的所有内容,另一个包含我的应用程序的“入职”/教程。

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

这是我导航到其他故事板的代码:

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
}

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

swift xcode firebase uiviewcontroller uistoryboard
1个回答
2
投票

当您展示入职时,您应该返回带有的标签

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)

onbarding内部的流程应该是pushViewController

然后在最后的入职vc中解雇

  if let tab =  (UIApplication.shared.delegate as! AppDelegate).window?.rootViewController as? UITabBarController {
     tab.dismiss(animated:true,completion:nil)
  } 
© www.soinside.com 2019 - 2024. All rights reserved.