Swift 为什么按下按钮后第二个计时器不启动/标签不更新?
我有一段代码:Swift 为什么按下按钮后第二个计时器不启动/标签不更新?,swift,Swift,我有一段代码: @IBAction func startbtn(_ sender: Any) { display = Int(timeinput.text ?? "") ?? 0 secondDisplay = Int(insertSecondTime.text ?? "") ?? 0 mytimer.invalidate() mytimer = Timer.scheduledTimer(timeInterval:
@IBAction func startbtn(_ sender: Any) {
display = Int(timeinput.text ?? "") ?? 0
secondDisplay = Int(insertSecondTime.text ?? "") ?? 0
mytimer.invalidate()
mytimer = Timer.scheduledTimer(timeInterval: 1, target: self, selector:
#selector(Action), userInfo: nil, repeats: true)
if display == 0 {
secondTimer.invalidate()
secondTimer = Timer.scheduledTimer(timeInterval: 1, target: self, selector:
#selector(Action2), userInfo: nil, repeats: true)
}
}
按下按钮时,第一次倒计时开始,但当第一次显示=0时,第二次倒计时不开始。有什么提示吗?这是不可复制的,但由于代码中的所有变量都是在startbtn函数的范围之外定义的,我们不知道它们是如何初始化的,以及它们可能在何时何地更改。请尝试提供您尝试的完整代码,以便有人可以帮助您解决您面临的问题