1

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.

rmaddy
  • 298,130
  • 40
  • 468
  • 517
KAVIYA VENKAT
  • 287
  • 2
  • 15
  • 1
    Have you tried to use the delegate pattern ? – Marwen Doukh Jun 03 '19 at 10:28
  • 2
    Use NotificationCenter to update the values – karthikeyan Jun 03 '19 at 10:48
  • Don't use NotificationCenter to post a notification to the entire application just for a child to pass data to its parent. Children should communicate with their parents through their intimate 1:1 relationship. `parentViewController` is an instance property of all view controllers that is nil by default (you can guess when it isn't nil). The delegate pattern was also made for these moments. – MJ-12 Jun 03 '19 at 16:46

1 Answers1

3

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
    }
Community
  • 1
  • 1
Samir Shaikh
  • 399
  • 2
  • 8