![](/img/trans.png)
[英]How to navigate to TabBar ViewController on click of button on popover ViewController in swift?
[英]Swift How to present Tabbar on Button click
在我的項目中,我想在按鈕單擊時顯示Tabbar,現在我已經創建了tabbar,我將身份名稱作為“tabbar”,我在下面的圖像中顯示
所以現在我使用下面的代碼來調用Tab欄控制器,但我沒有得到它。
let tabbar: UITabBarController? = (storyboard.instantiateViewController(withIdentifier: "tabbar") as? UITabBarController)
navigationController?.pushViewController(tabbar, animated: true)
你能告訴我我需要做什么,以及哪些代碼對我來說是有用的提示Tabbar控制器。
更多規格:我添加下面的圖像,其中一個viewController中有藍色按鈕我想在點擊該藍色按鈕時顯示標簽欄控制器
謝謝。
使用這個,你沒有那里的導航控制器,這就是為什么它不會這樣推,相反,你需要使用以下代碼:
self.present(tabbar, animated: true, completion: nil)
您應該知道Apple的HIG(人機接口指南)說如果您有一個選項卡式應用程序,它應該是整個應用程序的根級導航。 從人機界面的角度來看,你不應該做你想做的事情。
也就是說,技術上應該是可行的。
我的猜測是你沒有導航控制器。
使用調試器檢查self.navigationController
的值,或添加print語句:
let tabbar: UITabBarController? = (storyboard.instantiateViewController(withIdentifier: "tabbar") as? UITabBarController)
print("navigationController = \(navigationController)")
print("tabbar = \(tabbar)")
navigationController?.pushViewController(tabbar, animated: true)
如果navigationController
或tabbar
顯示為nil,那就是你的問題。
選擇觸發按鈕單擊的viewController,然后選擇Editor form form xcode menu-> Embed In-> NavigationController。
然后在按鈕操作中寫這個
let tabbar: UITabBarController? = (self.storyboard?.instantiateViewController(withIdentifier: "tabbar") as? UITabBarController)
self.navigationController?.pushViewController(tabbar!, animated: true)
根據你的圖像,我認為你的tabBarController沒有后退按鈕。 意味着用戶無法回頭。
如果是這種情況,你可以這樣做。
let tabBar = self.storyboard?.instantiateViewController(withIdentifier: "tabBar")
let appDelegate = UIApplication.shared.delegate as! AppDelegate
appDelegate.window?.rootViewController = tabBar
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.