2012-12-30 37 views
-1

可能重复:
Download image asynchronously如何下载多个图像asyncronously

我想异步下载多个图像。我有10个图像阵列,我想在10 uiimageview,我做这样的显示这些图片,但只显示一个图像

- (void)loadImage { 
    NSData* imageData = [[NSData alloc] initWithContentsOfURL:[NSURL URLWithString:[myarray objectatindex:0]]]; 
    UIImage* image = [[[UIImage alloc] initWithData:imageData] autorelease]; 
    [imageData release]; 
    [self performSelectorOnMainThread:@selector(displayImage:) withObject:image waitUntilDone:NO]; 
} 

The final method we need to create takes in the image to display and sets it on our image view. 

- (void)displayImage:(UIImage *)image { 
    [imageView setImage:image]; //UIImageView 
} 

所以,请你告诉我,我怎么能显示不同的多张图片,而无需创建10不同的方法。

回答

1

请勿使用同步的NSDatainitWithContentsOfURL方法。

你可能想要考虑UIImageView + AFNetworking类别,你可以找到here,它增加了UIImageView异步检索其内容的能力。

正如评论中的建议,你也可以看看SDWebImage,它基本上是一样的。

+0

是的,这可能是最好的办法,作为替代方案,你可以使用SDWebImage,你可以找到https://github.com/rs/SDWebImage – mohacs

+0

我将如何使用该类 –

+0

@Adnan哪一个? –

0

只要把这些类放到你的项目中,你就必须导入一些类。 对于sdwebimage,你会得到一个uiimageview的方法,就像“loadimagefrom url:withplaceholderimage”,只是检查一次,我不记得方法的名称。

+0

很多错误,包括该sdwebimage文件,但我在这个文件中使用undeclare标识符_manager –

+0

很多错误你必须包括整个sdwebimage图书馆 – Exploring