Skip to content

Instantly share code, notes, and snippets.

@leejunkit
Created March 8, 2013 02:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save leejunkit/5113680 to your computer and use it in GitHub Desktop.
Save leejunkit/5113680 to your computer and use it in GitHub Desktop.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
NSString *imageURL = @"http://..."; //image URL gotten from Activity object
//get a reference to the image view
UIImageView *imageView = (UIImageView *)[cell viewWithTag:1]; //for example
//using the SDWebImage downloader, start downloading the image
SDWebImageManager *manager = [SDWebImageManager sharedManager];
[manager downloadWithURL:[NSURL URLWithString:imageURL]
options:0
progress:^(NSUInteger receivedSize, long long expectedSize) {
}
completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, BOOL finished) {
/**
We can do this because the block "captures" the
necessary variables in its context for reference
when it starts execution.
**/
NSArray *visibleIndexPaths = [tableView indexPathsForVisibleRows];
if ([visibleIndexPaths containsObject:indexPath]) {
imageView.image = image;
}
}];
//... more code in the method
return cell;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment