Do not init an activity indictor if image isn't downloading in demo app (good practice)

This commit is contained in:
Olivier Poitrey 2012-11-19 18:30:31 +01:00
parent a7af2a19e4
commit 1ec36c7c99
1 changed files with 12 additions and 5 deletions

View File

@ -33,13 +33,20 @@
{
if (self.imageURL)
{
UIActivityIndicatorView *activityIndicator;
[self.imageView addSubview:activityIndicator = [UIActivityIndicatorView.alloc initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray]];
activityIndicator.center = self.imageView.center;
[activityIndicator startAnimating];
[self.imageView setImageWithURL:self.imageURL placeholderImage:nil options:SDWebImageProgressiveDownload completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType)
__block UIActivityIndicatorView *activityIndicator;
[self.imageView setImageWithURL:self.imageURL placeholderImage:nil options:SDWebImageProgressiveDownload progress:^(NSUInteger receivedSize, long long expectedSize)
{
if (!activityIndicator)
{
[self.imageView addSubview:activityIndicator = [UIActivityIndicatorView.alloc initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray]];
activityIndicator.center = self.imageView.center;
[activityIndicator startAnimating];
}
}
completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType)
{
[activityIndicator removeFromSuperview];
activityIndicator = nil;
}];
}
}