Skip to content

Commit 1ec36c7

Browse files
author
Olivier Poitrey
committed
Do not init an activity indictor if image isn't downloading in demo app (good practice)
1 parent a7af2a1 commit 1ec36c7

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

Examples/SDWebImage Demo/DetailViewController.m

+12-5
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,20 @@ - (void)configureView
3333
{
3434
if (self.imageURL)
3535
{
36-
UIActivityIndicatorView *activityIndicator;
37-
[self.imageView addSubview:activityIndicator = [UIActivityIndicatorView.alloc initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray]];
38-
activityIndicator.center = self.imageView.center;
39-
[activityIndicator startAnimating];
40-
[self.imageView setImageWithURL:self.imageURL placeholderImage:nil options:SDWebImageProgressiveDownload completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType)
36+
__block UIActivityIndicatorView *activityIndicator;
37+
[self.imageView setImageWithURL:self.imageURL placeholderImage:nil options:SDWebImageProgressiveDownload progress:^(NSUInteger receivedSize, long long expectedSize)
38+
{
39+
if (!activityIndicator)
40+
{
41+
[self.imageView addSubview:activityIndicator = [UIActivityIndicatorView.alloc initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray]];
42+
activityIndicator.center = self.imageView.center;
43+
[activityIndicator startAnimating];
44+
}
45+
}
46+
completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType)
4147
{
4248
[activityIndicator removeFromSuperview];
49+
activityIndicator = nil;
4350
}];
4451
}
4552
}

0 commit comments

Comments
 (0)