【发布时间】: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