[英]Present Tab of TabBarController Through parent ViewController
我想呈現我的tabBarController的某個索引,但首先要通過另一個自定義的ViewController。
在上圖中。 我想呈現黃色viewcontroller,它會自動顯示我的TabBar控制器,但我希望標簽欄控制器顯示一個特定的索引。
我用以下代碼呈現黃色ViewController:
let storyBoard : UIStoryboard = UIStoryboard(name: "Main", bundle: nil)
let tbc = storyBoard.instantiateViewController(withIdentifier: "SWRevealViewController") as! SWRevealViewController
tbc.modalTransitionStyle = .crossDissolve
self.present(tbc, animated: true, completion: nil)
通常當我在tabBarController上顯示一個標簽時,我會使用以下代碼:
let tbc = self.storyboard!.instantiateViewController(withIdentifier: "MyTabController") as! UITabBarController
tbc.selectedIndex = 1
tbc.modalPresentationStyle = .overCurrentContext
tbc.modalTransitionStyle = .coverVertical
self.present(tbc, animated: true, completion: nil)
我將如何通過黃色viewcontroller加載標簽欄的特定索引? 它是一個帶有自定義segue的自定義類:
在這種情況下,我通常會將您想要的索引從黃色控制器傳遞給tabBarController(使用let,例如,一個實例變量)。 然后可以通過選項卡欄控制器將其設置為所需的索引。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.