如何将 UIButton 连接到选项卡栏控制器中的特定选项卡?

How can I connect a UIButton to a specific tab in my Tab Bar Controller?

我有一个有 2 个标签的 UITabBarController。每个选项卡都不同,但都可以选择在顶部创建一个新的 post。当我在任一视图上点击新的 post 按钮时,我都有相同的 ViewController Present Modally。如果我点击 cancel 按钮,它会消失并返回到正确的选项卡,没问题。但是,如果我点击 post 按钮,我希望它始终转到第一个选项卡。

如何以编程方式告诉它切换到

之前的第一个选项卡
self.dismissViewControllerAnimated(true, completion: nil) 

这是我的故事板

这是我点击 post 按钮时调用的代码:

@IBAction func accept(sender: AnyObject) {
    var currentUserLocation = getUserLocation()
    currentUserLocation.getUserCoordinates()

    let appDelegate  = UIApplication.sharedApplication().delegate as! AppDelegate
    var tabBarController = appDelegate.window!.rootViewController as! UITabBarController
    tabBarController.SelectedIndex = 0


    self.dismissViewControllerAnimated(true, completion: nil)


}

我遇到了错误:

'UITabBarController' does not have a member named 'SelectedIndex'

具有以下内容:

let appDelegate  = UIApplication.sharedApplication().delegate as! AppDelegate
var tabBarController = appDelegate.window!.rootViewController as! UITabBarController
tabBarController.selectedIndex = 0

索引 0 处的控制器对应最左侧的选项卡,索引 1 处的控制器对应右侧的下一个选项卡,依此类推。