【发布时间】:2016-01-11 03:36:55
【问题描述】:
我第一次使用 Unwind Segue 方法。我有多个视图控制器,如下图所示(其中一些当然显示)。在编辑配置文件中,我有一个完成按钮。单击后,我会触发一个 IBAction,该 IBAction 会触发 unwind segue。
这是导航栏中完成按钮的代码:
@IBAction func unwindToMainViews(sender: UIStoryboardSegue) {
//let sourceViewController = sender.sourceViewController
self.performSegueWithIdentifier("unwindToMainSegue", sender: self)
}
并且在
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject!)
我正在执行以下操作以将数据从编辑配置文件传递回主视图
if (segue.identifier == "unwindToMainSegue") {
// pass data to next view
let tabCtrl = segue.destinationViewController as! UITabBarController
let destinationVC = tabCtrl.viewControllers![0] as! HomeViewController
destinationVC.userObject = self.userObject;
}
当segue标识符匹配并执行代码(将userObject从这个控制器转移到另一个)时,它会触发错误:
无法将“app.EditProfileViewController”(0x100b99d80)类型的值转换为“UITabBarController”(0x104a1d030)。
如何解决此错误?我很惊讶,因为我正在向 UITabBarController 投射,所以认为它应该可以工作。
【问题讨论】:
-
抱歉,我不明白您的建议
-
你不返回UITabBarController,你返回触发原始segue的ViewController。
-
好的...因为我是 unwinding 的新手...你能告诉我如何修改它以返回触发原始 segue 的视图控制器吗?