1. The most straightforward method PerformSelector:withObject:afterDelay: The disadvantage of this approach: Write a method for the time delay 2. Use categories, execute with Bolck
on @implementationNSObject (Performblockafterdelay) Geneva Geneva- (void) Performblock: (void(^) (void)) BlockGenevaAfterdelay: (nstimeinterval) Delay to { .block =[[block copy] autorelease]; -[Self performselector: @selector (fireblockafterdelay:) ,Withobject:block theAfterdelay:delay];Ten } One A- (void) Fireblockafterdelay: (void(^) (void) ) Block { -block (); - } the - @end
3. Using GCD
1 void void (^block) (void)) 2 {3 dispatch_after (Dispatch_time (dispatch_time_now, nsec_per_sec*delay), 4 Dispatch_get_current_queue (), block); 5 }
Poolo: Note that the Dispatch_getcurrent_queue () method in the code has been killed in IOS6 now with Dispatch_get_global_queue (dispatch_queue_priority_ high,0) The first parameter is the priority, the second parameter is 0, or nil if you want to work with the interfacedispatch_get_main_queue(); Reference: http://www.cnblogs.com/guwandong/archive/2012/08/08/2626211.html
1 dispatch_after (Dispatch_time (Dispatch_time_now, nsec_per_sec*10), ^{2 Dispatch_async (Dispatch_get_main_queue (), ^{3 [self alertlabelwithstr:@ " Scheduled synchronization successful "];//Execution Method 4 }"; 5 });
The second parameter of Dispatch_time is how many nanoseconds execute
4. May not be a good way to use the completion parameter of animation
1 [UIView animatewithduration:0.0 delay:5.0 options:uiviewanimationoptionallowuserinteraction animations:^{2 } completion:^(BOOL finished) {3 // Do stuffhere4 }];
5. Using Nsoperationqueue, execute in the next main loop of the application:
1
This and call Performselector:with Afterdelay of 0.0f equivalent
Methods for delayed execution of iOS