IOS four ways to delay

Source: Internet
Author: User
Tags gcd

-(void) initblock{
Method of delay
1:GCD delay this way in the ability to select the thread to run in the number of parameters.

is a non-clogging operation that does not find a way to cancel the operation.
Double delay1=2.0;//setting delay time
dispatch_time_t poptime=dispatch_time (Dispatch_time_now, delay1 * nsec_per_sec);
Dispatch_after (Poptime, Dispatch_get_main_queue (), ^{
Uialertview *alert=[[uialertview alloc]initwithtitle:@ "" message:@ "gcd delay" delegate:self cancelbuttontitle:@ "OK" otherbuttontitles:@ "Cancel", nil];
[Alert show];
});
2:nstimer delay, this method requires that it must be run in the main thread. Otherwise, it is invalid. is a non-clogging mode of operation that can be invalidate by the Nstimer class-(void);
[Nstimer scheduledtimerwithtimeinterval:8.0f target:self selector: @selector (DELAYMETHOD2) Userinfo:nil Repeats:no];
3:performselector delay
[Self performselector: @selector (Delaymethod) Withobject:nil afterdelay:5.0f];
4:nsthread delay
[Nsthread sleepfortimeinterval:11.0f];
[Self delayMethod3];
}
-(void) delaymethod{
Uialertview *alert=[[uialertview alloc]initwithtitle:@ "" message:@ "performselector delay" delegate:self cancelbuttontitle:@ "OK" otherbuttontitles:@ "Cancel", nil];
[Alert show];
}
-(void) delaymethod2{
Uialertview *alert=[[uialertview alloc]initwithtitle:@ "" message:@ "Nstimer delay" delegate:self cancelButtonTitle:@ "OK" otherbuttontitles:@ "Cancel", nil];
[Alert show];
}
-(void) delaymethod3{
Uialertview *alert=[[uialertview alloc]initwithtitle:@ "" message:@ "nsthread delay" delegate:self cancelButtonTitle:@ "OK "otherbuttontitles:@" cancellation ", nil";
[Alert show];
}

IOS four ways to delay

Related Article

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.