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

标签 ios swift segue uicontainerview

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

相关文章:

iphone - 在没有按钮连接的情况下以编程方式执行 Segue?

ios - 在 Swift 中以编程方式使用 segues 传递信息

iphone - native UI 弹出窗口问题

ios - 获取元素的当前约束

c# - 适用于 iOS 和 .Net 的类似 UI

ios - 传递闭包稍后调用

swift - 使用 AVAssetExportSession 将 MP4 转换为 WAV

ios - 如何在 iOS UI 的后台线程中处理和显示返回的异步数据

swift - 滚动条错误地显示在 UICollectionView 部分标题下方

ios - 我想创建一个标签来跟踪访问 View Controller 的次数