diff --git a/SDWebImage/UIView+WebCache.m b/SDWebImage/UIView+WebCache.m index 289c90e3..cb470c6c 100644 --- a/SDWebImage/UIView+WebCache.m +++ b/SDWebImage/UIView+WebCache.m @@ -23,6 +23,14 @@ const int64_t SDWebImageProgressUnitCountUnknown = 1LL; objc_setAssociatedObject(self, @selector(sd_imageURL), sd_imageURL, OBJC_ASSOCIATION_RETAIN_NONATOMIC); } +- (nullable NSString *)sd_latestOperationKey { + return objc_getAssociatedObject(self, @selector(sd_latestOperationKey)); +} + +- (void)setSd_latestOperationKey:(NSString * _Nullable)sd_latestOperationKey { + objc_setAssociatedObject(self, @selector(sd_latestOperationKey), sd_latestOperationKey, OBJC_ASSOCIATION_COPY_NONATOMIC); +} + - (NSProgress *)sd_imageProgress { NSProgress *progress = objc_getAssociatedObject(self, @selector(sd_imageProgress)); if (!progress) { @@ -48,6 +56,7 @@ const int64_t SDWebImageProgressUnitCountUnknown = 1LL; if (!validOperationKey) { validOperationKey = NSStringFromClass([self class]); } + self.sd_latestOperationKey = validOperationKey; [self sd_cancelImageLoadOperationWithKey:validOperationKey]; self.sd_imageURL = url; @@ -171,7 +180,7 @@ const int64_t SDWebImageProgressUnitCountUnknown = 1LL; } - (void)sd_cancelCurrentImageLoad { - [self sd_cancelImageLoadOperationWithKey:NSStringFromClass([self class])]; + [self sd_cancelImageLoadOperationWithKey:self.sd_latestOperationKey]; } - (void)sd_setImage:(UIImage *)image imageData:(NSData *)imageData basedOnClassOrViaCustomSetImageBlock:(SDSetImageBlock)setImageBlock cacheType:(SDImageCacheType)cacheType imageURL:(NSURL *)imageURL {