Skip to content

Commit

Permalink
Merge pull request SDWebImage#2386 from zhongwuzw/fix-nullable
Browse files Browse the repository at this point in the history
Fix nullable key when cancel image load operation
  • Loading branch information
bpoplauschi authored Jul 18, 2018
2 parents 98a2d9a + 593feb6 commit dbbfbd7
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 13 deletions.
3 changes: 1 addition & 2 deletions SDWebImage/UIImageView+WebCache.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:MyIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:MyIdentifier]
autorelease];
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:MyIdentifier];
}
// Here we use the provided sd_setImageWithURL: method to load the web image
Expand Down
25 changes: 14 additions & 11 deletions SDWebImage/UIView+WebCacheOperation.m
Original file line number Diff line number Diff line change
Expand Up @@ -42,18 +42,21 @@ - (void)sd_setImageLoadOperation:(nullable id<SDWebImageOperation>)operation for
}

- (void)sd_cancelImageLoadOperationWithKey:(nullable NSString *)key {
// Cancel in progress downloader from queue
SDOperationsDictionary *operationDictionary = [self sd_operationDictionary];
id<SDWebImageOperation> operation;
@synchronized (self) {
operation = [operationDictionary objectForKey:key];
}
if (operation) {
if ([operation conformsToProtocol:@protocol(SDWebImageOperation)]){
[operation cancel];
}
if (key) {
// Cancel in progress downloader from queue
SDOperationsDictionary *operationDictionary = [self sd_operationDictionary];
id<SDWebImageOperation> operation;

@synchronized (self) {
[operationDictionary removeObjectForKey:key];
operation = [operationDictionary objectForKey:key];
}
if (operation) {
if ([operation conformsToProtocol:@protocol(SDWebImageOperation)]) {
[operation cancel];
}
@synchronized (self) {
[operationDictionary removeObjectForKey:key];
}
}
}
}
Expand Down

0 comments on commit dbbfbd7

Please sign in to comment.