Skip to content

Instantly share code, notes, and snippets.

@alexito4
Created September 1, 2012 18:22
Show Gist options
  • Save alexito4/3582382 to your computer and use it in GitHub Desktop.
Save alexito4/3582382 to your computer and use it in GitHub Desktop.
AFNetworking - UIImageView+AFNetworking - New method setImageURL + blocks
/*
If you want to use blocks the only method that works is:
setImageWithURLRequest:placeholderImage:success:failure:
But you don't want to use URLRequest!
*/
// .h
- (void)setImageWithURL:(NSURL *)url
placeholderImage:(UIImage *)placeholderImage
success:(void (^)(NSURLRequest *request, NSHTTPURLResponse *response, UIImage *image))success
failure:(void (^)(NSURLRequest *request, NSHTTPURLResponse *response, NSError *error))failure;
// .m
- (void)setImageWithURL:(NSURL *)url
placeholderImage:(UIImage *)placeholderImage
success:(void (^)(NSURLRequest *request, NSHTTPURLResponse *response, UIImage *image))success
failure:(void (^)(NSURLRequest *request, NSHTTPURLResponse *response, NSError *error))failure
{
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:30.0];
[request setHTTPShouldHandleCookies:NO];
[request setHTTPShouldUsePipelining:YES];
[self setImageWithURLRequest:request placeholderImage:placeholderImage success:success failure:failure];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment