[英]How can i return to Main.storyboard which contains a TabBarController from another Storyboard
我有兩個分鏡腳本,一個包含應用程序真正的所有內容,另一個包含我的應用程序的“入門” /教程。
教程完成后,我想導航回到我原來的視圖控制器。
這是我的代碼,可以導航到其他故事板:
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?
當您顯示onbaording時,應使用
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一起使用
然后在最后一個onbaording vc中關閉
if let tab = (UIApplication.shared.delegate as! AppDelegate).window?.rootViewController as? UITabBarController {
tab.dismiss(animated:true,completion:nil)
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.