[Ios] ios delayed execution method and ios delayed execution Method
1. the most direct method is javasmselector: withObject: afterDelay: the disadvantage of this method: Write a method for the delay each time. use class and use BOLCK to execute [Code] c #/cpp/oc code:
01 |
@implementation NSObject (PerformBlockAfterDelay) |
03 |
- (void)performBlock:(void (^)(void))block |
04 |
afterDelay:(NSTimeInterval)delay |
06 |
block = [[block copy] autorelease]; |
07 |
[self performSelector:@selector(fireBlockAfterDelay:) |
12 |
- (void)fireBlockAfterDelay:(void (^)(void))block { |
3. Use GCD [Code] c #/cpp/oc code:
1 |
void RunBlockAfterDelay(NSTimeInterval delay, void (^block)(void)) |
3 |
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, NSEC_PER_SEC*delay), |
4 |
dispatch_get_current_queue(), block); |
Poolo: note that the dispatch_getcurrent_queue () method in the figure has been kill in ios6. Now the first parameter of dispatch_get_global_queue (DISPATCH_QUEUE_PRIORITY_HIGH, 0) is priority, the second parameter is 0 or nil if you want to operate on the interface, use dispatch_get_main_queue (); reference: http://www.cnblogs.com/guwandong/archive/2012/08/08/2626211.html 4. this may not be a good method. Use the [Code] c #/cpp/oc code of the completion parameter of animation:
1 |
[UIView animateWithDuration:0.0 delay:5.0 options:UIViewAnimationOptionAllowUserInteraction animations:^{ |
2 |
} completion:^(BOOL finished) { |
5. Use NSOperationQueue to run in the next main loop of the application: [Code] c #/cpp/oc code:
1 |
[[NSOperationQueue mainQueue] addOperationWithBlock:aBlock]; |
This is equivalent to calling mongomselector: with afterDelay of 0.0f.
In iOS, how does one implement a function to set the time to complete, for example, execute-(void) stop; it takes 5 seconds, so it may not be executed
[Self defined mselector: @ selector (function name) withObject: nil afterDelay: 5.0f]
Condition: in the main thread of uiviewController
[NSTimer scheduledTimerWithTimeInterval: 5.0f target: self selector: @ selector (function name) userInfo: nil repeats: NO]; in a specific function, run the code, call NSTimer invalidate to destroy timer after execution.
[NSThread sleepForTimeInterval: 5.0f]; [method for delayed execution];
Condition: the master thread or sub-thread can
The didSelectRowAtIndexPath method of UITableView is developed for IOS.
What are the operations on clicking cell? Is the operation complicated? If there is no operation, it should respond immediately. What does the static table mean? It is also related to poor machines. If you do not have much data, you should respond immediately. If you click cell to make a response to bring up a page, and the page Initialization is very complex, it will not pop up immediately.