Skip to content
This repository has been archived by the owner on Jan 17, 2023. It is now read-only.

Commit

Permalink
[Issue #592][Issue #600] Changes the logic of UIImageView -setImageWi…
Browse files Browse the repository at this point in the history
…thURLRequest:placeholderImage:success:failure: such that if the success block is specified, the default behavior of self.image = image is not executed. This allows for full customization over any post-processing on the image, or the animation to be used when setting the image.
  • Loading branch information
mattt committed Oct 31, 2012
1 parent ebc9f7d commit 81f33ae
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 9 deletions.
2 changes: 2 additions & 0 deletions AFNetworking/UIImageView+AFNetworking.h
Expand Up @@ -60,6 +60,8 @@
@param placeholderImage The image to be set initially, until the image request finishes. If `nil`, the image view will not change its image until the image request finishes.
@param success A block to be executed when the image request operation finishes successfully, with a status code in the 2xx range, and with an acceptable content type (e.g. `image/png`). This block has no return value and takes three arguments: the request sent from the client, the response received from the server, and the image created from the response data of request. If the image was returned from cache, the request and response parameters will be `nil`.
@param failure A block object to be executed when the image request operation finishes unsuccessfully, or that finishes successfully. This block has no return value and takes three arguments: the request sent from the client, the response received from the server, and the error object describing the network or parsing error that occurred.
@discussion If a success block is specified, it is the responsibility of the block to set the image of the image view before returning. If no success block is specified, the default behavior of setting the image with `self.image = image` is executed.
*/
- (void)setImageWithURLRequest:(NSURLRequest *)urlRequest
placeholderImage:(UIImage *)placeholderImage
Expand Down
19 changes: 10 additions & 9 deletions AFNetworking/UIImageView+AFNetworking.m
Expand Up @@ -114,23 +114,24 @@ - (void)setImageWithURLRequest:(NSURLRequest *)urlRequest
AFImageRequestOperation *requestOperation = [[AFImageRequestOperation alloc] initWithRequest:urlRequest];
[requestOperation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject) {
if ([[urlRequest URL] isEqual:[[self.af_imageRequestOperation request] URL]]) {
self.image = responseObject;
if (success) {
success(operation.request, operation.response, responseObject);
} else {
self.image = responseObject;
}

self.af_imageRequestOperation = nil;
}

if (success) {
success(operation.request, operation.response, responseObject);
}

[[[self class] af_sharedImageCache] cacheImage:responseObject forRequest:urlRequest];
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
if ([[urlRequest URL] isEqual:[[self.af_imageRequestOperation request] URL]]) {
if (failure) {
failure(operation.request, operation.response, error);
}

self.af_imageRequestOperation = nil;
}

if (failure) {
failure(operation.request, operation.response, error);
}
}];

self.af_imageRequestOperation = requestOperation;
Expand Down

0 comments on commit 81f33ae

Please sign in to comment.