UIDatePicker 在第一次触摸时没有响应

UIDatePicker not responding on first touch

我在情节提要中有一个倒数计时器 UIDatePicker。我用 @IBAction func 将它连接到我的主 ViewController.swift 文件,它会监听值更改事件。该函数在我第一次更改 UIDatePicker 时不会被调用,但会在后续值更改时被调用。

我怎样才能让它在第一次值变化时发生变化?

附加代码:

var timeRemaining: TimeInterval = 0.0

@IBOutlet weak var testTimeLabel: UILabel!
@IBOutlet weak var timeRemainingLabel: UILabel!

@IBAction func focusTimeSelected(_ sender: UIDatePicker) {
    timeRemaining = focusTimeDatePicker.countDownDuration
    testTimeLabel.text = String(timeRemaining)
    timeRemainingLabel.text = String(timeRemaining)
}

尝试更改

timeRemaining = focusTimeDatePicker.countDownDuration

timeRemaining = sender.countDownDuration