0

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"

        }
    }
Community
  • 1
  • 1
Nazmul Hasan
  • 10,130
  • 7
  • 50
  • 73

2 Answers2

2

You can get the vc with dcTabBar.viewControllers?[0] (replace 0 with index) or just dcTabBar.selectedViewController if its the first tabbar item

Tj3n
  • 9,837
  • 2
  • 24
  • 35
0

See if it working for you:

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
      }
    }
User511
  • 1,456
  • 10
  • 28