Skip to content

Commit

Permalink
Clean up.
Browse files Browse the repository at this point in the history
  • Loading branch information
samvermette committed Jun 19, 2012
1 parent 4b63a70 commit d5c6115
Showing 1 changed file with 14 additions and 15 deletions.
29 changes: 14 additions & 15 deletions SVPullToRefresh/SVPullToRefresh.m
Expand Up @@ -27,6 +27,9 @@ - (void)rotateArrow:(float)degrees hide:(BOOL)hide;
- (void)setScrollViewContentInset:(UIEdgeInsets)contentInset;
- (void)scrollViewDidScroll:(CGPoint)contentOffset;

- (void)startObservingScrollView;
- (void)stopObservingScrollView;

@property (nonatomic, copy) void (^pullToRefreshActionHandler)(void);
@property (nonatomic, copy) void (^infiniteScrollingActionHandler)(void);
@property (nonatomic, readwrite) SVPullToRefreshState state;
Expand All @@ -44,7 +47,7 @@ - (void)scrollViewDidScroll:(CGPoint)contentOffset;

@property (nonatomic, assign) BOOL showsPullToRefresh;
@property (nonatomic, assign) BOOL showsInfiniteScrolling;
@property (nonatomic, assign) BOOL observingScrollView;
@property (nonatomic, assign) BOOL isObservingScrollView;

@end

Expand All @@ -57,7 +60,7 @@ @implementation SVPullToRefresh

@synthesize state;
@synthesize scrollView = _scrollView;
@synthesize arrow, arrowImage, activityIndicatorView, titleLabel, dateLabel, originalScrollViewContentInset, originalTableFooterView, showsPullToRefresh, showsInfiniteScrolling, observingScrollView;
@synthesize arrow, arrowImage, activityIndicatorView, titleLabel, dateLabel, originalScrollViewContentInset, originalTableFooterView, showsPullToRefresh, showsInfiniteScrolling, isObservingScrollView;

- (void)dealloc {
[self stopObservingScrollView];
Expand All @@ -77,13 +80,11 @@ - (id)initWithScrollView:(UIScrollView *)scrollView {
return self;
}

- (void)willMoveToSuperview:(UIView *)newSuperview
{
if ( newSuperview == self.scrollView ) {
- (void)willMoveToSuperview:(UIView *)newSuperview {
if(newSuperview == self.scrollView)
[self startObservingScrollView];
} else if ( newSuperview == nil ) {
else if(newSuperview == nil)
[self stopObservingScrollView];
}
}

- (void)layoutSubviews {
Expand Down Expand Up @@ -254,24 +255,22 @@ - (void)setShowsInfiniteScrolling:(BOOL)show {

#pragma mark -

- (void)startObservingScrollView
{
if ( self.observingScrollView )
- (void)startObservingScrollView {
if (self.isObservingScrollView)
return;

[self.scrollView addObserver:self forKeyPath:@"contentOffset" options:NSKeyValueObservingOptionNew context:nil];
[self.scrollView addObserver:self forKeyPath:@"frame" options:NSKeyValueObservingOptionNew context:nil];
self.observingScrollView = YES;
self.isObservingScrollView = YES;
}

- (void)stopObservingScrollView
{
if ( self.observingScrollView )
- (void)stopObservingScrollView {
if(self.isObservingScrollView)
return;

[self.scrollView removeObserver:self forKeyPath:@"contentOffset"];
[self.scrollView removeObserver:self forKeyPath:@"frame"];
self.observingScrollView = NO;
self.isObservingScrollView = NO;
}

- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context {
Expand Down

0 comments on commit d5c6115

Please sign in to comment.