我在滚动视图中有图像数组。我点击图片时想从网址上传更大的图片。 例如,我点击图像“page-001.jpg”,然后检查图像数据,然后在图像视图上上传更大的图像并返回选项,以便返回上一个图像视图。
答案 0 :(得分:1)
试试这个
NSMutableArray *arr = [[NSArray alloc] initWithObjects:imageURL,imageView.tag, nil];
[self performSelectorInBackground:@selector(loadImageInBackground:) withObject:arr];
- (void) loadImageInBackground:(NSArray *)urlAndTagReference
{
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
// Retrieve the remote image. Retrieve the imgURL from the passed in array
NSURL *imgUrl=[[NSURL alloc] initWithString:[urlAndTagReference objectAtIndex:0]];
NSData *imgData = [NSData dataWithContentsOfURL:imgUrl];
UIImage *img = [UIImage imageWithData:imgData];
[imgUrl release];
// Create an array with the URL and imageView tag to
// reference the correct imageView in background thread.
NSMutableArray *arr = [[NSMutableArray alloc ] initWithObjects:img,[urlAndTagReference objectAtIndex:1], nil ];
// Image retrieved, call main thread method to update image, passing it the downloaded UIImage
[self performSelectorOnMainThread:@selector(assignImageToImageView:) withObject:arr waitUntilDone:YES];
[arr release];
[pool release];
}
- (void) assignImageToImageView:(NSMutableArray *)imgAndTagReference
{
UIImageView *profilePic = (UIImageView *)[cell.contentView viewWithTag:20];
imageView.image = [imgAndTagReference objectAtIndex:0];
}
答案 1 :(得分:1)
您可以使用SDWebImage。只需将文件添加到项目中并使用
即可[UIImageview setImageWithURL:(NSURL*)url];
这个库也管理缓存,在UITableViewCell中运行良好。