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

时间:2017-09-14 06:31:58

标签: ios swift interface-builder uidatepicker

我在故事板中有一个倒数计时器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)
}

1 个答案:

答案 0 :(得分:0)

尝试更改

timeRemaining = focusTimeDatePicker.countDownDuration

timeRemaining = sender.countDownDuration