gpt4 book ai didi

ios - 如何在不使用 swift 按钮的情况下将数据传递给另一个 ViewController

转载 作者:行者123 更新时间:2023-11-29 01:16:41 25 4
gpt4 key购买 nike

我目前有这个 Swift 代码,它不会将存储在 Score 中的 int 值传递到 currentScorehigherScore高分currentScorehighScore 均在 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
}
}

我目前正在使用 Storyboard推送到下一个 View 。这是推送代码。

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
}
}

关于ios - 如何在不使用 swift 按钮的情况下将数据传递给另一个 ViewController,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35098262/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com