-(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