ios - swift 2.0 prepareForSegue 不工作

标签 ios swift class viewcontroller

我正在尝试在我制作的应用程序中使用 prepareForSegue。 prepare forSegue 必须将一个类传递给单独的 View Controller 。这是 prepareForSegue

中的代码
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
    if segue.identifier == "createPieceSegue" {
        var svc = segue.destinationViewController as DestinationViewController!

        svc.pieceBaseClass = myClass
    }
}

这些是第一个 View Controller 继承自的父类(super class):

class ViewController: UIViewController, UIPickerViewDelegate, UIPickerViewDataSource, UITableViewDataSource, UITableViewDelegate, UINavigationBarDelegate

并且目标 View Controller 仅继承自 UIViewController。我不断收到的错误是:UIViewController is not convertible to'DestinationViewController' 因此我无法在两者之间传递数据。这个错误是什么意思,我该如何解决?

最佳答案

这意味着您还没有在 Storyboard中设置目标 VC 的自定义类。所以它只是一个 UIViewController 而不是你的子类。

关于ios - swift 2.0 prepareForSegue 不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33451967/

相关文章:

objective-c - 确定 UIViewController 是否以模态方式呈现

objective-c - __unsafe_unretained 代表不会建立

c++ - 如何从成员函数中获取私有(private)数据? C++

python - 在 Python 中如何从使用函数列表过渡到使用类?

ios - 如何在 iOS 的多 channel 混音器中实现缓冲?

ios - *修改* UIbutton位置(Iphone SDK)

swift - 在 Swift 中覆盖父类(super class)初始值设定项

ios - 如何在没有发送者的情况下将Target添加到UIButton

ios - 点击播放按钮闪烁停止

java - 我该如何让这个 'monster fight simulator' 工作?