异步加载多个图像到单个单元

问题描述:

我有一个加载5个图像到TableView的每个单元的问题。我用AFNetworking下载和setImageWithUrl方法imageView异步加载多个图像到单个单元

for (int i = 0; i < urls.count; i++) { 
    [self.photoImageView[i] setImageWithURL:urls[i]]; 
} 

TableView非常刹车,当我把它的滚动。但是当我尝试加载1或2时滚动没有刹车。 enter image description here 如何更正没有刹车的下载图像?

+0

image without break? –

+0

尝试设置'tableView.separatorStyle = UITableViewCellSeparatorStyleNone;' –

+0

它打破原因图像尺寸更大,所以尽量减少它。 –

我认为这对我的代码工作有帮助。

首先你使用这个库SDWebImage 然后执行下面的代码。

#import <SDWebImage/UIImageView+WebCache.h> 
... 
[cell.imageView sd_setImageWithURL:[NSURL URLWithString:@"URL"] 
      placeholderImage:[UIImage imageNamed:@"placeholder.png"]]; 

您可以使用@Ravi讨论的SDWebImage。您可以在for循环中使用上面的代码来异步显示所有5个图像,而不会阻塞主线程。

for (int i = 0; i < urls.count; i++) { 
[self.photoImageView[i] sd_setImageWithURL:[NSURL URLWithString:urls[i]] 
     placeholderImage:[UIImage imageNamed:@"placeholder.png"]]; 
} 

如果你不想使用任何第三方库,你也可以使用GCD相同。检查这ans

希望它有帮助。快乐编码!

如果你看到UIImage + AFNetworking类,它内部加载图像使用异步NSOperations.Try加载图像的特定dimensions.It将下载图像的大小&可以提高滚动性能。

NSMutableString *newURLPath = [NSMutableString stringWithString[exercise.imageURL absoluteString]]; 
[newURLPath appendFormat:@"?width=200&"]; 
[newURLPath appendFormat:@"height=200"]; 

For downloading the Asynchronous image from url, use any of these library for improving the scroll performance

SDWebImage - 异步图像下载使用缓存的支持作为一个UIImageView类。

#import <SDWebImage/UIImageView+WebCache.h> 
... 
[imageView sd_setImageWithURL:URL 
      placeholderImage:[UIImage imageNamed:@"placeholder.png"] 
]; 

PINRemoteImage - 它下载一个渐进式JPEG并获得吸引人的模糊更新。

对于你的情况,你可以去SDWebImage。

For Advance Concept, you could look into this one. 

AsyncDisplayKit - 适用于iOS光滑异步用户界面的应用程式

即使最近,Pinterest的是建立在AsyncDisplayKit以保持用户界面平滑和响应的顶部。 阅读这篇文章的更多信息:https://medium.com/@Pinterest_Engineering/re-architecting-pinterest-039-s-ios-app-e0a2d34a6ac2