几种创建定时器的比较

+ (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中,相当于做了两步。

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容