【发布时间】:2011-07-05 10:58:24
【问题描述】:
我在滚动视图中有图像数组。当我点击图片时,我想从 url 上传更大的图片。 例如,我点击图像“page-001.jpg”然后检查图像数据,然后在图像视图上上传更大的图像并返回选项,以便返回到以前的图像视图。
【问题讨论】:
标签: iphone xcode uiview uiscrollview xcode4
我在滚动视图中有图像数组。当我点击图片时,我想从 url 上传更大的图片。 例如,我点击图像“page-001.jpg”然后检查图像数据,然后在图像视图上上传更大的图像并返回选项,以便返回到以前的图像视图。
【问题讨论】:
标签: iphone xcode uiview uiscrollview xcode4
试试这个
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];
}
【讨论】:
您可以使用SDWebImage。只需将文件添加到您的项目并使用
[UIImageview setImageWithURL:(NSURL*)url];
这个库还管理缓存,并且在 UITableViewCell 中运行良好。
【讨论】: