3

我在 LocationVC ViewController 上有一个变量“NameofCircle”,我在这个控制器上有变量 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)
            }
}
4

2 回答 2

7

尝试这个。

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

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

if let   myController  = self.navigationController?.viewControllers[0] as? LocationVC
  {
    myController.NameofCircle = CName
   _ =  self.navigationController?.popToViewController(myController, animated: true)
    }
于 2017-03-08T10:53:18.057 回答
0

只需更换您的线路:

_ = self.navigationController?.popToViewController(aViewController,动画:真)

有了这个:

_ = self.navigationController?.popToViewController(位置,动画:真)

于 2017-03-08T11:59:14.320 回答