From 1ec36c7c9902c793d5608f2595e7aaa0c8e6889f Mon Sep 17 00:00:00 2001 From: Olivier Poitrey Date: Mon, 19 Nov 2012 18:30:31 +0100 Subject: [PATCH] Do not init an activity indictor if image isn't downloading in demo app (good practice) --- Examples/SDWebImage Demo/DetailViewController.m | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/Examples/SDWebImage Demo/DetailViewController.m b/Examples/SDWebImage Demo/DetailViewController.m index cd026eb..0d23f88 100644 --- a/Examples/SDWebImage Demo/DetailViewController.m +++ b/Examples/SDWebImage Demo/DetailViewController.m @@ -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; }]; } }