Skip to content

Instantly share code, notes, and snippets.

@soffes
Created May 29, 2012 05:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save soffes/2822776 to your computer and use it in GitHub Desktop.
Save soffes/2822776 to your computer and use it in GitHub Desktop.
@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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment