gpt4 book ai didi

ios - 尝试将数据传递到容器 View ,而 segue 不起作用

转载 作者:行者123 更新时间:2023-11-28 15:40:41 25 4
gpt4 key购买 nike

我正在尝试通过准备 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com