为什么我不能将根视图中的数据分配到其嵌入式容器视图中?

时间:2018-05-26 13:56:15

标签: arrays swift segue uicontainerview childviewcontroller

我的DetailViewController有一个container视图。将出现的第一个容器视图是DetailChildViewController

DetailChildViewController由一个集合视图组成,该视图将显示子视图的属性。但是,即使我在prepare(for segue :)函数中将数据分配给detailChildVC的属性,DetailChildViewController中的属性变量仍为returns nil。我该如何解决这个问题?

override func prepare(for segue: UIStoryboardSegue, sender: Any?) {

        // Set the currentViewController to description child VC because that is the first one
        // shown in the container view
        if segue.identifier == "DetailChildSegue" {
            let detailChildVC = DetailChildViewController()
            // Set product of the childVC
            let actionArray = [product?.action.keys.description] as? [String]
            detailChildVC.properties = actionArray
        }
        // Set the currentVC
        currentVC = segue.destination
    }

1 个答案:

答案 0 :(得分:0)

您指定新的DetailChildViewController()而不是目的地

override func prepare(for segue: UIStoryboardSegue, sender: Any?) {

    if segue.identifier == "DetailChildSegue" {

        let detailChildVC = segue.destination as! DetailChildViewController

        let actionArray = [product?.action.keys.description] as? [String]

        detailChildVC.properties = actionArray
    }

    // Set the currentVC

    currentVC = segue.destination
}