forked from steipete/PSFoundation
-
Notifications
You must be signed in to change notification settings - Fork 0
/
UITableViewCell+FKLoading.m
58 lines (42 loc) · 1.62 KB
/
UITableViewCell+FKLoading.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#import "UITableViewCell+FKLoading.h"
#import "NSObject+AssociatedObjects.h"
static char activityViewKey;
static char previousAccessoryKey;
@interface UITableViewCell ()
// re-define as read/write
@property (nonatomic, retain, readwrite) UIActivityIndicatorView *activityView;
@property (nonatomic, retain) UIView *previousAccessory;
@end
@implementation UITableViewCell (FKLoading)
- (void)showLoadingIndicator {
if ([self.accessoryView isKindOfClass:[UIActivityIndicatorView class]]) {
return;
}
// store previous accessoryView
self.previousAccessory = self.accessoryView;
// set activityIndicator as new accessoryView
self.activityView = [[[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhite] autorelease];
[self.activityView startAnimating];
self.accessoryView = self.activityView;
[self setNeedsDisplay];
}
- (void)hideLoadingIndicator {
[self.activityView stopAnimating];
// restore previous state
self.accessoryView = self.previousAccessory;
self.activityView = nil;
self.previousAccessory = nil;
}
- (void)setActivityView:(UIActivityIndicatorView *)activityView {
[self associateValue:activityView withKey:&activityViewKey];
}
- (UIActivityIndicatorView *)activityView {
return (UIActivityIndicatorView *)[self associatedValueForKey:&activityViewKey];
}
- (void)setPreviousAccessory:(UIView *)previousAccessory {
[self associateValue:previousAccessory withKey:&previousAccessoryKey];
}
- (UIView *)previousAccessory {
return (UIView *)[self associatedValueForKey:&previousAccessoryKey];
}
@end