我正在尝试通过准备 segue 将用户 ID 传递给容器 View
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
if segue.identifier == "childSegue" {
if let destinationVC = self.childViewControllers.first as? InterestCollectionController {
destinationVC.currentUser = self.currentUser
}
}
}
然而,这是行不通的。我的 Storyboard看起来像这样。 storyboard我也尝试过使用 segue.destination 作为! InterestCollectionController 并且它也不起作用。据我了解,这是我应该将数据传递到容器 View 的方式。感谢您的帮助!
最佳答案
在不使用 if 语句的情况下试试这个:
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
if segue.identifier == "childSegue" {
let destinationVC = segue.destinationViewController as InterestCollectionController
destinationVC.currentUser = self.currentUser
}
}
<强>1。确保您的 segue 标识符与 Storyboard标识符匹配。
<强>2。一旦您在 Storyboard中为上述 Controller 提供了准确的 segue,还要进行验证。
关于ios - 尝试将数据传递到容器 View ,而 segue 不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43738455/