提问人:Majed Alrajab 提问时间:5/12/2023 最后编辑:Peter MortensenMajed Alrajab 更新时间:5/12/2023 访问量:26
计时器在范围内找不到
Timer can not find in scope
问:
这段代码哪里出了问题?
@IBAction func startButton(_ sender: UIButton) {
var timer = Timer.scheduledTimer(timeInterval: 1, target: self, selector: #selector(update), userInfo: nil, repeats: true)
}
@objc func update() {
if (counter > 0) {
print(counter)
counter = counter - 1
progreesBar.progress = 1.0 - Float(counter)/Float(seconds)
}
else {
timer?.invalidate()
}
}
此代码未按预期工作。我该如何解决?
答: 暂无答案
评论
IB