ios - 通过 popToViewController 在 swift 中传递变量值

标签 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)
            }
}

最佳答案

试试这个。

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

关于ios - 通过 popToViewController 在 swift 中传递变量值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42669289/

相关文章:

ios - IPAD AIR iOS 8.0.2 版本设备的 Facebook 分享不显示初始文本

ios - 如何通过硬件解码在 iOS 上解码 H.264 帧?

iphone - 如何在 iphone 中通过电子邮件发送 .caf 文件?

ios - 如何在 Swift 中保持 UITextView 中 HTML 内容的缩进?

iphone - 在大数组中搜索字符串需要很长时间

swift - 如何计算在 iOS 的 CollectionView 中调用 indexpath 的次数?

ios - 在 swift 模块(框架)中使用依赖

ios - 3 个文本字段,1 个 pickerview,但是,使用 pickerView 时,选择内容不会显示在文本字段中

ios - Afnetworking 在 IOS 中抛出错误

iphone - iOS 编程建议请求 REF sqlite/iOS 应用程序设计