【发布时间】:2017-05-02 12:54:43
【问题描述】:
我正在尝试通过准备 segue 将用户 ID 传递给容器视图
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 我也尝试过使用 segue.destination 作为! InterestCollectionController 这也不起作用。据我了解,这是我应该将数据传递到我的容器视图的方式。感谢任何帮助!
【问题讨论】:
-
写得好像让destinationVC = segue.destinationViewCONtroller 一样? InterestCollectionController {destinationVC.currentUser = self.currentUser }
-
在容器视图中,我试图打印出 id 以确保它正确传递,但是在展开可选值时意外发现错误。
-
你在'self.currentUser'中有任何用户ID吗?请检查。
-
我在 self.currentUser 中有一个值。
-
ok.. 请在您的目标类中检查“currentUser”。您是否已标记为可选?如果是,那么请在您的目标类中将其作为非选项说 var myString = String()
标签: ios swift segue uicontainerview