Pass data between ViewController and TabBarController

后端 未结 4 1524
旧巷少年郎
旧巷少年郎 2021-02-09 07:07

I have couple of questions. How to pass the data (which i got after the Alamofire request is finished), to one of children of TabBarController?

The first problem i have

4条回答
  •  眼角桃花
    2021-02-09 07:40

    You don't necessarily need to use prepareForSegue for this. Just reference which ViewController in the TabBarController viewControllers array that you want and cast it.

    let vc = self.tabBarController.viewControllers![1] as! HomeViewController
    vc.templateForCell = templates
    

    If the ViewControllers in your TabBar are embedded in Navigation Controllers, you can do this:

    let navController = self.tabBarController.viewControllers![1] as! UINavigationController
    let vc = navController.topViewController as! HomeViewController
    vc.templateForCell = templates
    

提交回复
热议问题