1、初始化
+ (NSTimer
+ (NSTimer
注意:userInfo是值NSTimer携带的用户信息。
不用scheduled方式初始化的,需要手动addTimer:forMode:将timer添加到一个runloop中。
而scheduled的初始化方法将以默认mode直接添加到当前的runloop中.
sample:
或
NSTimer *myTimer
[[NSRunLoopcurrentRunLoop]
2、触发(启动)
当定时器创建完(不用scheduled的,添加到runloop中后,该定时器将在初始化时指定的timeInterval秒后自动触发。
可以使用-(void)fire;方法来立即触发该定时器;
注:You can use this method to fire arepeating timer without interrupting its regular firing schedule.If the timer is non-repeating, it is automatically invalidatedafter firing, even if its scheduled fire date has notarrived.
在重复执行的定时器中调用此方法后立即触发该定时器,但不会中断其之前的执行计划;
在不重复执行的定时器中调用此方法,立即触发后,就会使这个定时器失效。
3、停止
- (void)invalidate;
这个是唯一一个可以将计时器从runloop中移出的方法。