我在故事板中有一个倒数计时器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)
}
答案 0 :(得分:0)
尝试更改
timeRemaining = focusTimeDatePicker.countDownDuration
到
timeRemaining = sender.countDownDuration