I want to do the following:
I tried:
- (void)setImageWithURL:(NSURL *)url
placeholderImage:(UIImage *)placeholderImage
But I couldn't figure out how to handle the failure event.
Why don't you use
setImageWithURLRequest:placeholderImage:success:failure:
And set the wanted placeholder image in the fail block?
Example:
NSURLRequest * aURLRequest = [[NSURLRequest alloc] initWithURL:[[NSURL alloc] initWithString: @"A-URL"]];
UIImageView * img = [[UIImageView alloc] init];
__weak UIImageView* weakImg = img;
[img setImageWithURLRequest:aURLRequest
placeholderImage:nil
success:^(NSURLRequest *request, NSHTTPURLResponse *response, UIImage *image) {
//default
}
failure:^(NSURLRequest *request, NSHTTPURLResponse *response, NSError *error) {
weakImg.image = [UIImage imageNamed:@"fallbackImage"];
}];