How to refresh parentViewContoller from childViewContoller in swift?

坚强是说给别人听的谎言 提交于 2020-01-06 04:40:27

问题


I used XLPagerTabStrip for TabBar Refer.

Now I am doing some functionality in childViewController based upon that I need to update that value to UILabel in parent ViewController.

For Example: I am getting the values in childviewcontroller now I want to update that value in parentviewcontroller as mention in the below screenshot.


回答1:


If you don't want to use delegate then here is other solution CallBack

In child view controller create callback function like below

var callback: ((_ count: Int) -> Void)?

Use it when you need to update parent data

callback?(5)

In Parent view controller when your setting your child view controller or creating instance of child view at that time write below code.

    childVC.callback = { (count) -> Void in
        print(count)
        //update your cart label count
    }


来源:https://stackoverflow.com/questions/56425344/how-to-refresh-parentviewcontoller-from-childviewcontoller-in-swift

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!