TabBarController的Present选项卡通过父ViewController

时间:2017-01-17 22:51:04

标签: ios swift segue

我想提供tabBarController的某个索引,但首先要浏览另一个自定义ViewController。

enter image description here

在上图中。我想呈现黄色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的自定义类:

1 个答案:

答案 0 :(得分:0)

在这种情况下,我通常会将您想要的索引从黄色控制器传递给tabBarController(使用let,例如,一个实例变量)。然后,标签栏控制器可以将其设置为您想要的索引。