简体   繁体   中英

Passing data from child VC to parent VC ,simultaneously value reflection on both VCs

I am stuck on one issue, I have a following case

  1. I have a Parent VC

  2. It has 2 containers [childVC A, childVC B]

  3. API is calling on childVC (UIViewController) A

  4. As soon as childVC A receives response, half response should be populated on same childVC A and half response should be populated on its Parent VC [at same time, without using segue]

For this I have gone through the delegate and protocol methodology using this , they have used the segue, I don't want the segue.

Example perspective, I have gone through the example of Add To Cart methodology in which user will select the product from childVC and value will be added to the cart of parent VC

Adding the api call inside the child makes you have to use the delegate or access the parent if it's the rootvc , instead make the call inside the parent and use this to access the child

if let child1 =  self.children.first as?  FirstVC { // suppose it's at index 0
     // send the data to child 
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM