Skip to content

Commit 6698910

Browse files
committed
Revert "Loading Indicator view with 2 lines of code"
This reverts commit 2cfa5cc.
1 parent 2cfa5cc commit 6698910

File tree

3 files changed

+3
-85
lines changed

3 files changed

+3
-85
lines changed

Examples/SDWebImage Demo/MasterViewController.m

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -377,10 +377,6 @@ - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(N
377377
if (cell == nil)
378378
{
379379
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
380-
// show activity indicator
381-
[cell.imageView setShowActivityIndicatorView:YES];
382-
// choose indicator style
383-
[cell.imageView setIndicatorStyle:UIActivityIndicatorViewStyleGray];
384380
}
385381

386382
cell.textLabel.text = [NSString stringWithFormat:@"Image #%ld", (long)indexPath.row];

SDWebImage/UIImageView+WebCache.h

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -176,16 +176,4 @@
176176

177177
- (void)sd_cancelCurrentAnimationImagesLoad;
178178

179-
/**
180-
* Show activity UIActivityIndicatorView
181-
*/
182-
- (void)setShowActivityIndicatorView:(BOOL)show;
183-
184-
/**
185-
* set desired UIActivityIndicatorViewStyle
186-
*
187-
* @param style The style of the UIActivityIndicatorView
188-
*/
189-
- (void)setIndicatorStyle:(UIActivityIndicatorViewStyle)style;
190-
191179
@end

SDWebImage/UIImageView+WebCache.m

Lines changed: 3 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,6 @@
1111
#import "UIView+WebCacheOperation.h"
1212

1313
static char imageURLKey;
14-
static char TAG_ACTIVITY_INDICATOR;
15-
static char TAG_ACTIVITY_STYLE;
16-
static char TAG_ACTIVITY_SHOW;
1714

1815
@implementation UIImageView (WebCache)
1916

@@ -50,19 +47,13 @@ - (void)sd_setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder
5047
self.image = placeholder;
5148
});
5249
}
53-
54-
// check if activityView is enabled or not
55-
if ([self showActivityIndicatorView]) {
56-
[self addActivityIndicator];
57-
}
58-
50+
5951
if (url) {
6052
__weak UIImageView *wself = self;
6153
id <SDWebImageOperation> operation = [SDWebImageManager.sharedManager downloadImageWithURL:url options:options progress:progressBlock completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, BOOL finished, NSURL *imageURL) {
6254
if (!wself) return;
6355
dispatch_main_sync_safe(^{
6456
if (!wself) return;
65-
[wself removeActivityIndicator];
6657
if (image) {
6758
wself.image = image;
6859
[wself setNeedsLayout];
@@ -80,7 +71,6 @@ - (void)sd_setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder
8071
[self sd_setImageLoadOperation:operation forKey:@"UIImageViewImageLoad"];
8172
} else {
8273
dispatch_main_async_safe(^{
83-
[self removeActivityIndicator];
8474
NSError *error = [NSError errorWithDomain:@"SDWebImageErrorDomain" code:-1 userInfo:@{NSLocalizedDescriptionKey : @"Trying to load a nil url"}];
8575
if (completedBlock) {
8676
completedBlock(nil, error, SDImageCacheTypeNone, url);
@@ -92,8 +82,8 @@ - (void)sd_setImageWithURL:(NSURL *)url placeholderImage:(UIImage *)placeholder
9282
- (void)sd_setImageWithPreviousCachedImageWithURL:(NSURL *)url andPlaceholderImage:(UIImage *)placeholder options:(SDWebImageOptions)options progress:(SDWebImageDownloaderProgressBlock)progressBlock completed:(SDWebImageCompletionBlock)completedBlock {
9383
NSString *key = [[SDWebImageManager sharedManager] cacheKeyForURL:url];
9484
UIImage *lastPreviousCachedImage = [[SDImageCache sharedImageCache] imageFromDiskCacheForKey:key];
95-
96-
[self sd_setImageWithURL:url placeholderImage:lastPreviousCachedImage ?: placeholder options:options progress:progressBlock completed:completedBlock];
85+
86+
[self sd_setImageWithURL:url placeholderImage:lastPreviousCachedImage ?: placeholder options:options progress:progressBlock completed:completedBlock];
9787
}
9888

9989
- (NSURL *)sd_imageURL {
@@ -139,60 +129,4 @@ - (void)sd_cancelCurrentAnimationImagesLoad {
139129
[self sd_cancelImageLoadOperationWithKey:@"UIImageViewAnimationImages"];
140130
}
141131

142-
- (UIActivityIndicatorView *)activityIndicator {
143-
return (UIActivityIndicatorView *)objc_getAssociatedObject(self, &TAG_ACTIVITY_INDICATOR);
144-
}
145-
- (void)setActivityIndicator:(UIActivityIndicatorView *)activityIndicator {
146-
objc_setAssociatedObject(self, &TAG_ACTIVITY_INDICATOR, activityIndicator, OBJC_ASSOCIATION_RETAIN);
147-
}
148-
149-
- (void)setShowActivityIndicatorView:(BOOL)show{
150-
objc_setAssociatedObject(self, &TAG_ACTIVITY_SHOW, [NSNumber numberWithBool:show], OBJC_ASSOCIATION_RETAIN);
151-
}
152-
- (BOOL)showActivityIndicatorView{
153-
return [objc_getAssociatedObject(self, &TAG_ACTIVITY_SHOW) boolValue];
154-
}
155-
156-
- (void)setIndicatorStyle:(UIActivityIndicatorViewStyle)style{
157-
objc_setAssociatedObject(self, &TAG_ACTIVITY_STYLE, [NSNumber numberWithInt:style], OBJC_ASSOCIATION_RETAIN);
158-
}
159-
- (int)getIndicatorStyle{
160-
return [objc_getAssociatedObject(self, &TAG_ACTIVITY_STYLE) intValue];
161-
}
162-
163-
- (void)addActivityIndicator {
164-
if (!self.activityIndicator) {
165-
self.activityIndicator = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:[self getIndicatorStyle]];
166-
self.activityIndicator.autoresizingMask = UIViewAutoresizingNone;
167-
168-
dispatch_async(dispatch_get_main_queue(), ^(void) {
169-
[self addSubview:self.activityIndicator];
170-
[self updateActivityIndicatorFrame];
171-
});
172-
}
173-
174-
dispatch_async(dispatch_get_main_queue(), ^(void) {
175-
[self.activityIndicator startAnimating];
176-
});
177-
178-
}
179-
- (void)updateActivityIndicatorFrame {
180-
if (self.activityIndicator) {
181-
CGRect activityIndicatorBounds = self.activityIndicator.bounds;
182-
float x = (self.frame.size.width - activityIndicatorBounds.size.width) / 2.0;
183-
float y = (self.frame.size.height - activityIndicatorBounds.size.height) / 2.0;
184-
self.activityIndicator.frame = CGRectMake(x, y, activityIndicatorBounds.size.width, activityIndicatorBounds.size.height);
185-
}
186-
}
187-
- (void)removeActivityIndicator {
188-
if (self.activityIndicator) {
189-
[self.activityIndicator removeFromSuperview];
190-
self.activityIndicator = nil;
191-
}
192-
}
193-
- (void)layoutSubviews {
194-
[super layoutSubviews];
195-
[self updateActivityIndicatorFrame];
196-
}
197-
198132
@end

0 commit comments

Comments
 (0)