使用InstantiateViewController传递数据

时间:2017-03-08 07:12:43

标签: xcode swift3

我有这个代码但是,我没有收到第二个视图控制器中的数据......我在这里做错了什么?

        let storyboard = UIStoryboard(name: "PostSubmit", bundle: nil)
        let vc = storyboard.instantiateViewController(withIdentifier: "PostSubmitVC") as! PostSubmitViewController {
            let nc = UINavigationController(rootViewController: vc)
            vc.filteredResult = filteredResult
        }
        self.present(nc, animated: false, completion: nil)

1 个答案:

答案 0 :(得分:1)

可能问题是你提出的错误的控制器nc值是否在块内部,并且它不在块的旁边。

 let vc = storyboard.instantiateViewController(withIdentifier: "PostSubmitVC") as! PostSubmitViewController 
 let nc = UINavigationController(rootViewController: vc)
 vc.filteredResult = filteredResult 
 self.present(nc, animated: false, completion: nil)