Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

allow imageRequestOperation to be cancelled

  • Loading branch information...
commit bd6fc88c014f0b8149a45a5340f11c4d0e1c27c7 1 parent 714ccc1
@steipete steipete authored
Showing with 13 additions and 8 deletions.
  1. +13 −8 AFNetworking/UIImageView+AFNetworking.m
View
21 AFNetworking/UIImageView+AFNetworking.m
@@ -87,6 +87,9 @@ - (void)setImageWithURL:(NSURL *)url
block:(void (^)(UIImage *image))block
{
if (!url) {
+ // stop loading image
+ [self.imageRequestOperation cancel];
+ self.imageRequestOperation = nil;
return;
}
@@ -105,14 +108,16 @@ - (void)setImageWithURL:(NSURL *)url
self.image = placeholderImage;
self.imageRequestOperation = [AFImageRequestOperation operationWithRequest:request imageSize:imageSize options:options success:^(UIImage *image) {
- if ([[request URL] isEqual:[[self.imageRequestOperation request] URL]]) {
- self.image = image;
- } else {
- self.image = placeholderImage;
- }
-
- if (block) {
- block(image);
+ if (self.imageRequestOperation && ![self.imageRequestOperation isCancelled]) {
+ if ([[request URL] isEqual:[[self.imageRequestOperation request] URL]]) {
+ self.image = image;
+ } else {
+ self.image = placeholderImage;
+ }
+
+ if (block) {
+ block(image);
+ }
}
}];
Please sign in to comment.
Something went wrong with that request. Please try again.