Reputation: 255
am using https://github.com/xmartlabs/XLPagerTabStrip and i have 3 children ... i want to pass value from child to child ..
am able to pass value from parent to first child like this:
let parentVC = self.parent as! ParentViewController
mobile = parentVC.mobile
but now i want to pass it from child 1 to child 2 .. tried the above but i got that mobile is nil
and mobile in the parentview is declared like this:
var mobile = ""
how can i pass data between children?
override func viewControllers(for pagerTabStripController: PagerTabStripViewController) -> [UIViewController] {
let child1 = UIStoryboard(name: "Main", bundle: nil).instantiateViewController(withIdentifier: "cominfo")
let child2 = UIStoryboard(name: "Main", bundle: nil).instantiateViewController(withIdentifier: "comedu")
let child3 = UIStoryboard(name: "Main", bundle: nil).instantiateViewController(withIdentifier: "comcv")
return [child1,child2,child3]
}
Upvotes: 0
Views: 699
Reputation: 1
I was having the same issue until I found simple solution: I use singleton design pattern here by take instance from super class and set shared property over there and then it shared over all Childs
Upvotes: 0
Reputation: 756
override func viewControllers(for pagerTabStripController: PagerTabStripViewController) -> [UIViewController] {
let child1 = UIStoryboard(name: "Main", bundle: nil).instantiateViewController(withIdentifier: "cominfo") as! yourChildClassname
child1.mobile = self.mobile
let child2 = UIStoryboard(name: "Main", bundle: nil).instantiateViewController(withIdentifier: "comedu")as! yourChildClassname
child2.mobile = self.mobile
let child3 = UIStoryboard(name: "Main", bundle: nil).instantiateViewController(withIdentifier: "comcv") as! yourChildClassname
child3.mobile = self.mobile
return [child1,child2,child3]
}
Upvotes: 2