【发布时间】:2024-01-16 09:53:02
【问题描述】:
我希望 displayBatsmenOneScoreLabel 在按下 resetScoreButton 时重置为 0。
resetScoreButton 的代码是什么?
这是我的代码。
var batsmenOneScoreInt: Int = 0
@IBOutlet weak var displayBatsmenOneScoreLabel: UILabel!
@IBAction func BatsmenOneScoreStepper(_ sender: UIStepper) {
let batsmenOneScoreValue = Int(sender.value)
displayBatsmenOneScoreLabel.text = String(batsmenOneScoreValue)
}
@IBAction func resetScoreButton(_ sender: Any) {
//what should I write here...
}
【问题讨论】:
-
我猜他的问题是如何将按钮的标签重置为0。
-
JFI,您应该在编程中使用正确的命名约定。例如。在这种情况下,
BatsmenOneScoreStepper应该是batsmenOneScoreStepper。:) -
为什么只重置标签?为什么不同时重置 score 变量?
-
仅供参考 - 您的
batsmenOneScoreInt属性从未使用过。在BatsmenOneScoreStepper中创建一个同名的局部变量。
标签: ios swift uibutton uilabel