首页 > 解决方案 > 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()
}

}

标签: iosswiftxcodeuislider

解决方案


推荐阅读