Use of latency functions and nstimer

Source: Internet
Author: User

1. latency functions:
[Nsthread sleepfortimeinterval: 5.0]; // pause for 5 s.

2. Use of Timer:
Nstimer * connectiontimer; // timer object

For example:

// Initialize timer, @ selector (logo :), itsMediumThe method is automatically called after the past 1.5 seconds..

Self. connectiontimer = [nstimerscheduledtimerwithtimeinterval: 1.5 target: selfselector: @ selector (timerfired :) userinfo: Nil repeats: No];
[[Nsunloop currentrunloop] addtimer: Self. connectiontimer formode: nsdefaultrunloopmode];

 

// Use timer as a delay Method
Do {
[[Nsunloopcurrentrunloop] rununtildate: [nsdatewithtimeintervalsincenow: 1.0];
} While (! Done );

// Call the function by timer
-(Void) timerfired :( nstimer *) timer {
[Logo. View removefromsuperview];
[Timer invalidate];

// This sentenceCodeIt is used to terminate Timmer. Otherwise, this method will be executed once every 1.5 seconds. It is enough to be executed once at the beginning.

}

 

3. Execute the timecount method every 0.8 seconds.

Nstimer * counttimer;
Counttimer = [nstimerscheduledtimerwithtimeinterval: 0.8 target: selfselector: @ selector (timecount :) userinfo: nilrepeats: Yes];
[Counttimerfire];// Execute Timer

 

4. the test method is executed with a delay of 1 second:
[Selfperformselector: @ selector (TEST) withobject: nilafterdelay: 0.1];

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.