老实说,我无法弄清楚我做错了什么。我已经尝试了我能想到的每一个解决方案。老实说,我希望这很简单。无论如何,这是我目前的代码
@IBOutlet var tacScore: UILabel!
@IBOutlet var ticScore: UILabel!
var winCounter = 0
if gameState[combination[0]] == 1 {
winnerLabel.text = "Tac Wins!"
ticScore.text = "Tic:\(winCounter += 1)"
} else {
winnerLabel.text = "Tic Wins!"
ticScore.text = "Tic:\(winCounter += 1)"
}
我根本没有收到任何错误,但当有人在我的游戏中获胜时,得分标签也会改变Tic:()
和Tac:()
答案 0 :(得分:0)
您的代码应该是这样的:
var winCounter = 0
if gameState[combination[0]] == 1 {
winnerLabel.text = "Tac Wins!"
winCounter += 1
tacScore.text = "Tic:\(winCounter)"
}else{
winnerLabel.text = "Tic Wins!"
winCounter += 1
ticScore.text = "Tic:\(winCounter)"
}
这里的原因是表达式将在返回到.text指针的字符串后执行。您需要做的就是先计算它,然后更新标签。