Delay timer after first fire

前端 未结 2 1669
甜味超标
甜味超标 2021-01-07 01:51

I have a timer in my application that triggers a certain event:

myTimer =  NSTimer.scheduledTimerWithTimeInterval(10, target: self,
    selector: \"searchFor         


        
2条回答
  •  粉色の甜心
    2021-01-07 02:07

    First schedule the timer as you've done.

    timer =  NSTimer.scheduledTimerWithTimeInterval(
        10.0, target: self,
        selector: "searchForDrivers:",
        userInfo: nil,
        repeats: true
    )
    

    Then, immediately afterwards, fire timer.

    timer.fire()
    

    According to the documentation,

    You can use this method to fire a repeating timer without interrupting its regular firing schedule. If the timer is non-repeating, it is automatically invalidated after firing, even if its scheduled fire date has not arrived.

    See the NSTimer Class Reference for more information.

提交回复
热议问题