Reputation: 2738
I am trying to add a Success and Error block to check when the image is loaded so that I can use NSCache to dynamically resize the image. But when I try
[scribbleImage setImageWithURL: [NSURL URLWithString:scribble[@"scribble_image"]] placeholderImage:[UIImage imageNamed:@"Default.png"] success:^(UIImage *image) {
NSLog(@"done");
} failure:^(NSError *error) {
NSLog(@"error %@",error);
}];
Xcode gives me an error, saying No visible @interface for 'UIImageView' declares the selector 'setImageWithURL:placeholderImage:success:failure:'
I am not sure why.
PS. I am importing UIImageView+AFNetworking.h and things work just fine without a success and failure block
Upvotes: 0
Views: 2697
Reputation: 69469
This is because the there is no method setImageWithURL:placeholderImage:success:failure:
there is just setImageWithURLRequest:placeholderImage:success:failure:
NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:scribble[@"scribble_image"]]];
[scribbleImage setImageWithURLRequest:request placeholderImage:[UIImage imageNamed:@"Default.png"] success:^(NSURLRequest *request, NSHTTPURLResponse *response, UIImage *image) {
NSLog(@"Done");
} failure:^(NSURLRequest *request, NSHTTPURLResponse *response, NSError *error) {
NSLog(@"Failed with error: %@", error);
}];
If you look at what setImageWithURL:placeholderImage:
does :
- (void)setImageWithURL:(NSURL *)url
placeholderImage:(UIImage *)placeholderImage
{
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url];
[request setHTTPShouldHandleCookies:NO];
[request addValue:@"image/*" forHTTPHeaderField:@"Accept"];
[self setImageWithURLRequest:request placeholderImage:placeholderImage success:nil failure:nil];
}
You see that this is the method is used to fetch the internally as well.
Upvotes: 2