// 在主線程中延遲執(zhí)行某動作,不會卡主主線程,不影響后面的東做執(zhí)行
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(3 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
NSLog(@"%@", [NSThread currentThread]);
});
// 在子線程中執(zhí)行某動作,不會卡主整個(gè)線程
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(@"%@", [NSThread currentThread]);
});
// 實(shí)現(xiàn)延遲,該線程本身在哪個(gè)線程中就再哪個(gè)線程中執(zhí)行
NSURL *url = [NSURL URLWithString:@"http://59320.jpg.com"];
[self performSelector:@selector(download:) withObject:url afterDelay:3];
// 利用sleep實(shí)現(xiàn)延遲(不要用這個(gè),會卡住主線程,即后面的動作不會執(zhí)行)
[NSThread sleepForTimeInterval:3];