我目前有这个Swift代码,不会将存储在score中的int
值传递到currentScore
并将higherScore
传递到highScore
。 currentScore
和highScore
都在GameOverViewController
上实例化。
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
if segue.identifier == "GameOverVC" {
let svc: GameOverViewController = segue.destinationViewController as! GameOverViewController
score = svc.currentScore
higherScore = svc.highScore
}
}
我目前正在使用情节提要来推送到下一个视图。这是推送代码。
if let resultController = self.storyboard?.instantiateViewControllerWithIdentifier("GameOverVC") as? GameOverViewController {
self.presentViewController(resultController, animated: true, completion: nil)
}
所有代码都可以正常编译,所以我需要有一个实际的
UIButton
还是需要在方法或GameOverViewCotroller
中添加其他内容? 最佳答案
您分配值是错误的方式...
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
if segue.identifier == "GameOverVC" {
let svc: GameOverViewController = segue.destinationViewController as! GameOverViewController
svc.currentScore = score //pass self.score to svc.currentScore
svc.highScore = higherScore //pass self.higherScore to svc.currentScore
}
}