public
Created

  • Download Gist
erg.m
Objective-C
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
@interface SSPullToRefreshView ()
@property (nonatomic, weak, readwrite) UIScrollView *scrollView;
@end
 
@implementation SSPullToRefreshView
 
@synthesize scrollView = _scrollView;
 
- (void)setScrollView:(UIScrollView *)scrollView {
void *context = (__bridge void *)self;
[self.scrollView removeObserver:self forKeyPath:@"contentOffset" context:context];
_scrollView = scrollView;
_defaultContentInset = self.scrollView.contentInset;
[self.scrollView addObserver:self forKeyPath:@"contentOffset" options:NSKeyValueObservingOptionNew context:context];
}
 
- (void)dealloc {
self.scrollView = nil;
}
 
 
- (void)removeFromSuperview {
// _scrollView is nil already when this is called so removing the KVO doesn't do anything
self.scrollView = nil;
[super removeFromSuperview];
}
 
@end

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.