Allow nested call to setImageWithURLRequest
Calling [UIImageView setImageWithURL:] inside [UIImageView setImageWithURLRequest:placeholderImage:success:failure] completion block could NOT work. This was due to internal af_imageRequestOperation set to nil AFTER a completion block is called. With this fix, it is now set to nil BEFORE.
This commit is contained in:
parent
75bd257ffe
commit
1fc909e9db
1 changed files with 10 additions and 10 deletions
|
|
@ -101,13 +101,13 @@ static char kAFImageRequestOperationObjectKey;
|
||||||
|
|
||||||
UIImage *cachedImage = [[[self class] af_sharedImageCache] cachedImageForRequest:urlRequest];
|
UIImage *cachedImage = [[[self class] af_sharedImageCache] cachedImageForRequest:urlRequest];
|
||||||
if (cachedImage) {
|
if (cachedImage) {
|
||||||
|
self.af_imageRequestOperation = nil;
|
||||||
|
|
||||||
if (success) {
|
if (success) {
|
||||||
success(nil, nil, cachedImage);
|
success(nil, nil, cachedImage);
|
||||||
} else {
|
} else {
|
||||||
self.image = cachedImage;
|
self.image = cachedImage;
|
||||||
}
|
}
|
||||||
|
|
||||||
self.af_imageRequestOperation = nil;
|
|
||||||
} else {
|
} else {
|
||||||
if (placeholderImage) {
|
if (placeholderImage) {
|
||||||
self.image = placeholderImage;
|
self.image = placeholderImage;
|
||||||
|
|
@ -116,27 +116,27 @@ static char kAFImageRequestOperationObjectKey;
|
||||||
AFImageRequestOperation *requestOperation = [[AFImageRequestOperation alloc] initWithRequest:urlRequest];
|
AFImageRequestOperation *requestOperation = [[AFImageRequestOperation alloc] initWithRequest:urlRequest];
|
||||||
[requestOperation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject) {
|
[requestOperation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject) {
|
||||||
if ([urlRequest isEqual:[self.af_imageRequestOperation request]]) {
|
if ([urlRequest isEqual:[self.af_imageRequestOperation request]]) {
|
||||||
|
if (self.af_imageRequestOperation == operation) {
|
||||||
|
self.af_imageRequestOperation = nil;
|
||||||
|
}
|
||||||
|
|
||||||
if (success) {
|
if (success) {
|
||||||
success(operation.request, operation.response, responseObject);
|
success(operation.request, operation.response, responseObject);
|
||||||
} else if (responseObject) {
|
} else if (responseObject) {
|
||||||
self.image = responseObject;
|
self.image = responseObject;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (self.af_imageRequestOperation == operation) {
|
|
||||||
self.af_imageRequestOperation = nil;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[[[self class] af_sharedImageCache] cacheImage:responseObject forRequest:urlRequest];
|
[[[self class] af_sharedImageCache] cacheImage:responseObject forRequest:urlRequest];
|
||||||
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
|
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
|
||||||
if ([urlRequest isEqual:[self.af_imageRequestOperation request]]) {
|
if ([urlRequest isEqual:[self.af_imageRequestOperation request]]) {
|
||||||
if (failure) {
|
|
||||||
failure(operation.request, operation.response, error);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (self.af_imageRequestOperation == operation) {
|
if (self.af_imageRequestOperation == operation) {
|
||||||
self.af_imageRequestOperation = nil;
|
self.af_imageRequestOperation = nil;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (failure) {
|
||||||
|
failure(operation.request, operation.response, error);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}];
|
}];
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue