[英]Open another storyboard with tabbar and navigation bar
我正在另一個故事板中創建一個歡迎頁面我還有一個跳過按鈕,可以打開主故事板
在主故事板中,有一個minTabbar,每個選項卡都有自己的導航欄
這是我在跳過按鈕的acton中的代碼
var window: UIWindow?
let mainStoryBoard = UIStoryboard(name: "Main", bundle: nil)
@IBAction func skipButton(_ sender: UIButton) {
let todoTabBar = mainStoryBoard.instantiateViewController(withIdentifier: "mainTabBar") as! UITabBarController
todoTabBar.selectedIndex = 1
let nvc = todoTabBar.selectedViewController as? UINavigationController
nvc?.popToRootViewController(animated: false)
}
但它沒有工作,按下按鈕后沒有任何反應,你能幫助我嗎? 非常感謝
這個
let nvc = todoTabBar.selectedViewController as? UINavigationController
nvc?.popToRootViewController(animated: false)
使用當前未顯示/顯示的vc進行播放,以便所有操作都在動態,確保訪問真實的1或顯示todoTabBar
如果是這種情況
如果你需要離開演示vc做
self.present(todoTabBar,animated:true,completion:nil)
如果你需要制作todoTabBar
唯一贈送的1
(UIApplication.shared.delegate as! AppDelegate).window!.rootViewController = todoTabBar
您可以使用以下代碼更改根視圖控制器窗口:
let stotyBoard = UIStoryboard(name: "OtherStoryBoard", bundle: nil)
if let otherVC = stotyBoard.instantiateViewController(withIdentifier: "OtherViewController")
as? OtherViewController {
let appDelegate = UIApplication.shared.delegate as! AppDelegate
appDelegate.window = UIWindow(frame: UIScreen.main.bounds)
appDelegate.window?.rootViewController = otherVC
otherVC.selectedIndex = 0
appDelegate.window?.makeKeyAndVisible()
}
看起來像@Sh_khan已經為您提供了解決方案作為評論的一部分。 請接受這個答案。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.