Merge pull request #2386 from zhongwuzw/fix-nullable

Fix nullable key when cancel image load operation
This commit is contained in:
Bogdan Poplauschi 2018-07-18 18:28:00 +03:00 committed by GitHub
commit dbbfbd715a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 13 deletions

View File

@ -27,8 +27,7 @@
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:MyIdentifier]; UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:MyIdentifier];
if (cell == nil) { if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:MyIdentifier] cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:MyIdentifier];
autorelease];
} }
// Here we use the provided sd_setImageWithURL: method to load the web image // Here we use the provided sd_setImageWithURL: method to load the web image

View File

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