I'm trying to set an image on an ImageView
using AFNetworking's setImageWithURLRequest
on a tableViewCell. If I do not include the success
and failure
blocks in the method like so:
[cell.thumbnailImageView setImageWithURL:url placeholderImage:nil];
Everything works perfectly and the image sets. Unfortunately I need the blocks.
Here's what I currently have in cellForRowAtIndexPath
:
if (self.images) { //check if the array of images is set, fetched from a URL
NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString: [[self.images objectAtIndex:indexPath.row] objectForKey:@"tbUrl"]]];
[cell.thumbnailImageView setImageWithURLRequest:request placeholderImage:[UIImage imageNamed:@"placeholder"] success:^(NSURLRequest *request, NSHTTPURLResponse *response, UIImage *image) {
NSLog(@"success"); //it always lands here! But nothing happens
} failure:^(NSURLRequest *request, NSHTTPURLResponse *response, NSError *error) {
NSLog(@"fail");
}];
}
From UIImageView+AFNetworking.h
:
If a success block is specified, it is the responsibility of the block to set the image of the image view before returning.
In your success block, you need to say:
[cell.thumbnailImageView setImage: image]