Create a gist now

Instantly share code, notes, and snippets.

@soffes /erg.m
Created May 29, 2012

What would you like to do?
@interface SSPullToRefreshView ()
@property (nonatomic, weak, readwrite) UIScrollView *scrollView;
@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];
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment