iOS Development Nstimer

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.