多執行緒在專案中的使用
//1.獲取一個全域性序列佇列
dispatch_queue_t queue =dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT,0);
//2.把任務新增到佇列中執行
dispatch_async(queue, ^{
//列印當前執行緒
NSLog(@"currentThread --- %@",[NSThreadcurrentThread]);
//3.從網路上下載圖片
NSURL *url = [NSURLURLWithString:@"http://h.hiphotos.baidu.com/baike/w%3D268/sign=30b3fb747b310a55c424d9f28f444387/1e30e924b899a9018b8d3ab11f950a7b0308f5f9.jpg"
NSData *data = [NSDatadataWithContentsOfURL:url];
UIImage *image = [UIImageimageWithData:data];
NSLog(@"圖片載入完畢");
/*
//4.回主執行緒,展示圖片
[_imageV performSelectorOnMainThread:@selector(setImage:) withObject:image waitUntilDone:YES];
*/
dispatch_async(dispatch_get_main_queue(), ^{
_imageV.image = image;
//列印當前執行緒
NSLog(@"currentThread --- %@",[NSThreadcurrentThread]);
});
});