Several common methods of delaying execution in iOS

Source: Internet
Author: User

1.performSelector
[Self performselector: @selector (Delaymethod) withobject:nil/* can pass any type parameter * /Afterdelay: 2.0];

Note: This method is a non-blocking execution, and no method is found to cancel execution.

2.NSTimer Timer
Nstimer *timer = [Nstimer scheduledtimerwithtimeinterval:2.0 target:self selector: @selector (Delaymethod) Userinfo:nil Repeats:no];

Note: This method is a non-blocking execution mode,
Cancel execution method: - (void)invalidate; You can

3.NSThread Thread of Sleep
[Nsthread sleepfortimeinterval:2.0];

Note: This method is a blocking execution method that is recommended to be executed in a sub-thread, otherwise it will get stuck in the interface. However, sometimes it is necessary to block execution, such as entering the boot page (ad display) to sleep 2 seconds before entering the main interface.
The cancel execution method was not found.

4.GCD
__block Viewcontroller/* Host controller * /*weakself = = Dispatch_time (Dispatch_time_now, ( int64_t) (2.0 */* deferred execution time  */*^{    [weakself Delaymethod];}); `

Note: This method can select the executing thread in the parameter, which is a non-blocking execution mode. The cancel execution method was not found.

Several common methods of delaying execution in iOS

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.