我的scheduleTimer较弱:
weak var timer = Timer.scheduledTimer(timerInterval: 2.0, target: self, selector: #selector(fire), userInfo: ["id",id], repeats: false)
如果我启动此计时器并仅导航到一个viewController,它将在后台正常启动。但是,如果我在计时器触发之前导航到另一个viewController,它将永远不会熄灭。知道为什么会这样吗?
答案 0 :(得分:0)
class viewController: UIViewController
{
var timer = Timer()
func one()
{
timer = Timer.scheduledTimer(timeInterval: 2.0, target: self, selector: #selector(backClick), userInfo: ["id"], repeats: false)
}
func two()
{
timer = Timer.scheduledTimer(timeInterval: 2.0, target: self, selector: #selector(backClick), userInfo: ["id"], repeats: false)
}
inValidate()
计时器 override func viewDidDisappear(_ animated: Bool) {
super.viewDidDisappear(animated)
timer.fire()
}
答案 1 :(得分:-2)
因为像@Alexandr Kolesnik的评论那样微弱,或者当第一个消失时您可能无效。