Pass data from table view to tab bar display controller in Swift.

In my storyboard, I have a part that has a table view controller in front of the tab bar controller. This tab bar has two view controllers. I was already using a table view, and when I clicked on one cell, I went to another Viewcontroller, which loaded another view controller with a table and cells with ID from the pushed cell from the first table. Like this:

Table controller, prepare for the segue:

        if segue.identifier == "overviewSegue" {
          var caseViewController: CaseViewController = segue.destinationViewController as CaseViewController
          var caseIndex = overviewTableView!.indexPathForSelectedRow()!.row
          var selectedCase = self.cases[caseIndex]
        caseViewController.caseitem = selectedCase
    }

      

It works well. Now I want to do the same, but the only difference is that the last view controller is part of the panel controller. The problem is I can't get it to work to pass data to this last table view controller.

I have tried several things, but I cannot get the data into the tab table view. Segue are not available and the destination is not a table view controller but a tab controller etc. The question is how to pass data from a table using a panel controller to another view controller.

+3


source to share


1 answer


I found a solution:

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

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

        desView.caseitem = selectedCase
      }
    }

      



Simple explanation: you need to get to the panel controller and select its controllers. He usually has two, so you can choose the first one. After that, determine which class it belongs to and you can transfer your data just like before.

+6


source







All Articles