标签:
- 1.使用NSThread类
[NSThread sleepForTimeInterval:3];
该方法会阻塞当前线程
-2.使用NSObject中的方法
[self performSelector:@selector(download:) withObject:sender afterDelay:timeDelay];
该方法不会阻塞当前线程,在当前线程执行selector
-3.使用gcd
在主线程或由全局队列上的线程异步延迟回调block
dispatch_queue_t queue = dispatch_get_main_queue(); dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(3 * NSEC_PER_SEC)), queue, ^{ NSLog(@"------task------%@", [NSThread currentThread]); });
dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0); dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(3 * NSEC_PER_SEC)), queue, ^{ NSLog(@"------task------%@", [NSThread currentThread]); });
标签:
原文地址:http://www.cnblogs.com/forflame/p/4558380.html