【问题标题】:Error in passing data via prepare for segue通过准备 segue 传递数据时出错
【发布时间】:2017-03-02 19:27:46
【问题描述】:

我正在使用我的 prepare for segue 方法传递变量 x。代码如下:

override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
    if (segue.identifier == "Restartseg") {
        var x = 1
        let destinationVC = segue.destination as! GameViewController
        destinationVC.x = x
    }
    else if (segue.identifier == "Homeseg"){
        //pass more data
    }

}

但是在destinationVC.x = x线上有一个编译时错误说:

“GameViewController”类型的值没有成员“x”

但是,在类id下的Game view Controller文件中,我声明了变量x

class GameViewController: UIViewController {
var x:Int!   }

【问题讨论】:

  • 您的代码没有问题,尝试清理并重新构建。

标签: ios swift uiviewcontroller swift3


【解决方案1】:

改变这一行

let destinationVC = segue.destination as! GameViewController

进入

let destinationVC = segue.destinationViewController as! GameViewController

然后清理并构建项目。希望有效

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-11-30
    • 2019-05-11
    • 1970-01-01
    • 2017-10-21
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多