Passing data with segue through TabBarControllerController

时间:2016-11-09 08:22:12

标签: ios swift swift3 segue

Try this one Passing data with segue through navigationController but I need one more step before UITabBarController

enter image description here

ViewController->UITabBarController->UINavigationController->RestaurantTableViewController

The destination view controller of the segue is the UITabBarController. How can I get the real destination RestaurantTableViewController:

 override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
        if segue.identifier == segueIdentifire() {
            let dcTabBar = segue.destination as! UITabBarController
            let dcNabBar = //i don't know what should i write here? 
            let dc = dcNabBar.topViewController as! RestaurantTableViewController
            dc.dcTitle = "Restaurant"

        }
    }

2 个答案:

答案 0 :(得分:2)

如果第一个标签栏项目

,您可以使用dcTabBar.viewControllers?[0](将0替换为索引)或仅dcTabBar.selectedViewController获取vc

答案 1 :(得分:0)

看看它是否适合您:

override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
      if segue.identifier == "toTabController" {
        var tabBarC : UITabBarController = segue.destinationViewController as UITabBarController
        var desView: RestaurantTableViewController = tabBarC.viewControllers?.first as RestaurantTableViewController

        var caseIndex = overviewTableView!.indexPathForSelectedRow()!.row
        var selectedCase = self.cases[caseIndex]

        desView.caseitem = selectedCase
      }
    }