Clean delegates even on failed downloads

This commit is contained in:
Olivier Poitrey 2011-03-21 16:40:09 +01:00
parent 3116810b18
commit 44fd72843b
2 changed files with 39 additions and 2 deletions

View File

@ -138,9 +138,19 @@ static SDWebImageManager *instance;
{
id<SDWebImageManagerDelegate> delegate = [delegates objectAtIndex:idx];
if (image && [delegate respondsToSelector:@selector(webImageManager:didFinishWithImage:)])
if (image)
{
[delegate performSelector:@selector(webImageManager:didFinishWithImage:) withObject:self withObject:image];
if ([delegate respondsToSelector:@selector(webImageManager:didFinishWithImage:)])
{
[delegate performSelector:@selector(webImageManager:didFinishWithImage:) withObject:self withObject:image];
}
}
else
{
if ([delegate respondsToSelector:@selector(webImageManager:didFailWithError:)])
{
[delegate performSelector:@selector(webImageManager:didFailWithError:) withObject:self withObject:nil];
}
}
[downloaders removeObjectAtIndex:idx];
@ -168,5 +178,31 @@ static SDWebImageManager *instance;
[downloader release];
}
- (void)imageDownloader:(SDWebImageDownloader *)downloader didFailWithError:(NSError *)error;
{
[downloader retain];
// Notify all the delegates with this downloader
for (NSInteger idx = [downloaders count] - 1; idx >= 0; idx--)
{
SDWebImageDownloader *aDownloader = [downloaders objectAtIndex:idx];
if (aDownloader == downloader)
{
id<SDWebImageManagerDelegate> delegate = [delegates objectAtIndex:idx];
if ([delegate respondsToSelector:@selector(webImageManager:didFailWithError:)])
{
[delegate performSelector:@selector(webImageManager:didFailWithError:) withObject:self withObject:error];
}
[downloaders removeObjectAtIndex:idx];
[delegates removeObjectAtIndex:idx];
}
}
// Release the downloader
[downloaderForURL removeObjectForKey:downloader.url];
[downloader release];
}
@end

View File

@ -13,5 +13,6 @@
@optional
- (void)webImageManager:(SDWebImageManager *)imageManager didFinishWithImage:(UIImage *)image;
- (void)webImageManager:(SDWebImageManager *)imageManager didFailWithError:(NSError *)error;
@end