我目前有这个Swift代码,不会将存储在score中的int值传递到currentScore并将higherScore传递到highScorecurrentScorehighScore都在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
    }
}

08-26 03:42
查看更多