几种创建定时器的比较

+ (NSTimer*)timerWithTimeInterval:(NSTimeInterval)ti target:(id)aTarget selector:(SEL)aSelector userInfo:(nullable id)userInfo repeats:(BOOL)yesOrNo;

Initializes a timer object with the specified object and selector.

You must add the new timer to a run loop, using addTimer: forMode:. Then, after ti seconds have elapsed, the timer fires, sending the message aSelector to target. (If the timer is configured to repeat, there is no need to subsequently re-add the timer to the run loop.)

你必须把新创建的定时器添加到一个runloop中,然后定时器才会真正启动。

+ (NSTimer*)scheduledTimerWithTimeInterval:(NSTimeInterval)ti target:(id)aTarget selector:(SEL)aSelector userInfo:(nullable id)userInfo repeats:(BOOL)yesOrNo;

Creates a timer and schedules it on the current run loop in the default mode.

After ti seconds have elapsed, the timer fires, sending the message aSelector to target.

这个方法创建一个定时器,以default模式添加到当前的runloop中,相当于做了两步。

你可能感兴趣的:(几种创建定时器的比较)