为什么我不能将根视图中的数据分配到其嵌入式容器视图中?
Why can't I assign data from the root view onto its embedded container view?
我有一个 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
}
您分配给一个新变量 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
}
我有一个 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
}
您分配给一个新变量 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
}