使用XLPagerTabStrip在孩子之间传递数据

时间:2018-07-26 06:44:30

标签: ios swift xcode xlpagertabstrip

我使用https://github.com/xmartlabs/XLPagerTabStrip,我有3个孩子……我想将价值从一个孩子传递到另一个孩子..

能够像这样将值从父级传递给第一个孩子:

    let parentVC = self.parent as! ParentViewController
    mobile = parentVC.mobile

但是现在我想将其从孩子1传递给孩子2 ..尝试了以上操作,但我发现移动电话无效

enter image description here

,父视图中的移动设备声明如下:

    var mobile = ""

我如何在孩子之间传递数据?

       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

1 个答案:

答案 0 :(得分:1)

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