upload image from url in scroll view
I have array of image in scroll view. I want to upload bigger im开发者_如何学运维age from url when i tap on image. for example i tap on image"page-001.jpg" then check image data and then upload bigger image on image view and get back option so that go back to previous image view.
try this
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];
}
You can use SDWebImage. Just add the files to your project and use
[UIImageview setImageWithURL:(NSURL*)url];
This library also manage cache, and works very well in an UITableViewCell.
 
         加载中,请稍侯......
 加载中,请稍侯......
      
精彩评论