1, Nstimer is called "timer", its function is as follows
- Ø perform the specified task at the specified time
- Ø perform assigned tasks at every interval
2, call Nstimer The following method will open a timed task
+ (Nstimer *)scheduledtimerwithtimeinterval:(nstimeinterval) ti target: (ID) atarget selector: (SEL) Aselect or userInfo: (ID) userInfo
Repeats: (BOOL) Yesorno;
Every ti second, call a Atarget Aselector method, Yesorno determines whether to repeat the task
3, through the Invalidate method can stop the work of the timer, once the timer is stopped, you can not perform the task again. You can only create a new timer to perform a new task.
-(void) invalidate;
Note If there are other actions in the main thread, the Nstimer Scheduledtimerwithtimeinterval method pauses execution and the timer action continues after the related operation in the main thread finishes. For example, the above is the advertising carousel (with the timer to achieve the picture carousel effect), the following is UITableView, when we drag the UITableView, the above ad carousel is the pause carousel effect, the solution is to add the following code, Make the main thread do not pause the timer operation when handling other tasks:
[[Nsrunloop Mainrunloop] Addtimer:mytimer formode:
Nsrunloopcomonmodes];
iOS Development Nstimer