Pass data between ViewController and TabBarController

后端 未结 4 1467
旧巷少年郎
旧巷少年郎 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:33

    You could do something like this from the TabController class (parent):

    var maleVC: MaleOptionsViewController! //First child 
    var femaleVC: FemaleOptionsViewController! //Second child
    
    override func viewDidLoad() {
        super.viewDidLoad()
        maleVC = self.viewControllers![0] as? MaleOptionsViewController //Reference to first child
        femaleVC = self.viewControllers![1] as? FemaleOptionsViewController //Reference to second child
    }
    

    And pass it data like this:

    override func tabBar(_ tabBar: UITabBar, didSelect item: UITabBarItem) {
            maleVC.cartTableView?.reloadData() //Where cartTableView is an IBOutlet or even a variable for that matter
            femaleVC.cartTableView?.reloadData() //Same thing as the comment ^
    }
    

提交回复
热议问题