通过swift中的popToViewController传递变量值

时间:2017-03-08 10:51:16

标签: ios iphone swift poptoviewcontroller

我在LocationVC ViewController上有一个变量“NameofCircle”,我在这个Controller上有变量CName我想通过popToViewController将CName值传递给LocationVC Controller。我试过下面的代码,但没有得到结果。

let viewControllers = self.navigationController!.viewControllers
    for aViewController in viewControllers
    {
        if aViewController is LocationVC
        {
           let Location = LocationVC()
            Location.NameofCircle = CName
    _ = self.navigationController?.popToViewController(aViewController, animated: true)
            }
}

2 个答案:

答案 0 :(得分:4)

试试这个。

#adr

另一种选择将值传递给Root ViewController

#tel

答案 1 :(得分:0)

只需更换你的行:

_ = self.navigationController?.popToViewController(aViewController,animated:true)

这一个:

_ = self.navigationController?.popToViewController(Location,animated:true)