ios - Swift & Xcode:UISlider 不会在模拟构建中响应
问题描述
我正在构建一个小型圆盘高尔夫计分应用程序来跟踪两名球员在前九洞的进步。我认为我的逻辑是合理的,Xcode 中的 linter 没有发现任何错误,但我的 UISlider 不会在模拟构建中移动,并且相关的字符串插值也不会加载。任何人都可以帮忙吗?
// ViewController.swift
// DiscGolfScoresheet
import UIKit
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
updateHole()
}
// Holes available to play
let frontNineList = ["Hole 1", "Hole 2", "Hole 3", "Hole 4", "Hole 5", "Hole 6", "Hole 7", "Hole 8", "Hole 9"]
// Counter to track current hole in play
var currentHoleIndex = 0
// UI elements grouped
@IBOutlet weak var holeLabel: UILabel!
@IBOutlet weak var imageView: UIImageView!
@IBOutlet weak var oneScore: UILabel!
@IBOutlet weak var oneSlider: UISlider!
@IBOutlet weak var twoScore: UILabel!
@IBOutlet weak var twoSlider: UISlider!
// Variables to track players' scores through the rounds
var oneCurrentScore = 0
var twoCurrentScore = 0
// Action to track slider/score changes for player one
@IBAction func oneSliderChanged(_ sender: UISlider) {
let oneCurrentScore = Int(sender.value)
oneScore.text = "Player one's total score: \(oneCurrentScore)"
}
// Action to track slider/score changes for player two
@IBAction func twoSliderChanged(_ sender: UISlider) {
let twoCurrentScore = Int(sender.value)
twoScore.text = "Player two's total score: \(twoCurrentScore)"
}
// Function to cycle through all nine holes with associated pictures and labels
func updateHole() {
holeLabel.text = frontNineList[currentHoleIndex]
let holePicture = frontNineList[currentHoleIndex]
let image = UIImage(named: holePicture)
imageView.image = image
}
// Function to go to next hole when button is selected and to cycle through indefinitely
@IBAction func goToNextHole(_ sender: Any) {
currentHoleIndex += 1
if currentHoleIndex >= frontNineList.count {
currentHoleIndex = 0
}
updateHole()
}
}
解决方案
推荐阅读
- nativescript - 基于标签的导航路由困难
- oauth-2.0 - 在 Keycloak 中禁用刷新令牌
- ios - SKPaymentQueue canMakePayments() 在模拟器中返回什么?
- javascript - 工具提示位置不变 (D3)
- swift - 在 SwiftUI 中从视图中删除焦点环
- android - 即使我使用溢出属性,我的文本小部件也会溢出
- mysql - 在当前表中保存去年的值
- java - Android:RecyclerView 适配器在构造函数处停止
- api - 取决于用户的字段的后端访问权限
- python - Python:需要在不中断循环的情况下调用 API