-1

Possible Duplicate:
Download image asynchronously

I would like to download multiple images asynchronously. I have array of 10 images and I want to show these images in 10 uiimageview, I am doing like this but it show only one image

- (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
}

So kindly tell me how I can show multiple images on different without creating 10 different methods.

4

2 回答 2

1

Don't use the initWithContentsOfURL method of NSData, which is synchronous.

You may want to consider the UIImageView+AFNetworking category that you can find here, that adds to UIImageView the ability to retrieve its content asynchronously.

As suggested in the comments you can also look at SDWebImage, which does basically the same.

于 2012-12-30T12:54:48.503 回答
0

只需将这些类放入您的项目中,您就必须导入一些类。对于 sdwebimage,您将获得一个用于 uiimageview 的方法,类似于“loadimagefrom url:withplaceholderimage”,一旦我不记得方法名称就检查一下。

于 2012-12-30T13:55:12.623 回答