Lama
Lama

Reputation: 255

passing data between children using XLPagerTabStrip

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

enter image description here

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]
}

enter image description here

Upvotes: 0

Views: 699

Answers (2)

ahmed maher
ahmed maher

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

Shezad
Shezad

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

Related Questions