Tag: coco

从networking加载UIImage最常用的方法

亲爱的stackoverflowers, 我迷路了。 在我的应用程序中,我从网上加载2个图像,如下所示: -(void)loadImages { … image1 = [UIImage imageWithData:[NSData dataWithContentsOfURL:imgUrl1]]; image2 = [UIImage imageWithData:[NSData dataWithContentsOfURL:imgUrl2]]; } 为了不阻塞主线程,我使用GCD : dispatch_async( dispatch_get_global_queue(0,0), ^{ [self loadImages]; 之后,我在我的UITableView使用这些图像: if (indexPath.row == 0) { cell.imageView.image = image1; } else { cell.imageView.image = image2; } 然后我决定添加UIActivityIndicator ,但遇到了一些问题。 我明白我的代码是不正确的。 我看到人们使用NSURLRequest和NSURLConnection来加载图像并添加UIActivityIndicator 。 请告诉我,加载这样的图像最正规的方式是什么? 我应该重写什么?