Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Fixed bug where NSTimer was getting leaked

  • Loading branch information...
commit 420d1d31d4ebe2b2423c0245ded0806b10aeffea 1 parent 3354092
@thuss thuss authored
Showing with 10 additions and 16 deletions.
  1. +1 −11 PullToRefreshView.h
  2. +9 −5 PullToRefreshView.m
View
12 PullToRefreshView.h
@@ -38,21 +38,11 @@ typedef enum {
@protocol PullToRefreshViewDelegate;
@interface PullToRefreshView : UIView {
- id<PullToRefreshViewDelegate> delegate;
- UIScrollView *scrollView;
PullToRefreshViewState state;
-
- NSTimer *timer;
-
- UILabel *lastUpdatedLabel;
- UILabel *statusLabel;
- CALayer *arrowImage;
- UIActivityIndicatorView *activityView;
-
- NSDateFormatter *dateFormatter;
}
@property (nonatomic, retain) UIScrollView *scrollView;
+@property (nonatomic, retain) NSTimer *timer;
@property (nonatomic, assign) id<PullToRefreshViewDelegate> delegate;
@property (nonatomic, assign) NSTimeInterval timeout;
@property (nonatomic, retain) UILabel *lastUpdatedLabel;
View
14 PullToRefreshView.m
@@ -46,6 +46,7 @@ - (void)hide;
@end
@implementation PullToRefreshView
+@synthesize dateFormatter;
@synthesize delegate;
@synthesize scrollView;
@synthesize lastUpdatedLabel, statusLabel, arrowImage, activityView;
@@ -308,12 +309,12 @@ - (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(N
- (void)finishedLoading {
if (state == PullToRefreshViewStateLoading) {
- [timer invalidate];
[self dismissView];
}
}
- (void)dismissView {
+ [self stopTimer];
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.3f];
[self setState:PullToRefreshViewStateNormal];
@@ -326,10 +327,15 @@ - (void)dismissView {
- (void)startTimer {
if (self.timeout > 0) {
- timer = [[NSTimer scheduledTimerWithTimeInterval:self.timeout target:self selector:@selector(timerExpired:) userInfo:nil repeats:NO] retain];
+ self.timer = [NSTimer scheduledTimerWithTimeInterval:self.timeout target:self selector:@selector(timerExpired:) userInfo:nil repeats:NO];
}
}
+- (void)stopTimer {
+ [self.timer invalidate];
+ self.timer = nil;
+}
+
- (void)timerExpired:(NSTimer*)theTimer {
[self dismissView];
}
@@ -339,9 +345,7 @@ - (void)timerExpired:(NSTimer*)theTimer {
-(void)cleanUp {
delegate = nil;
- [timer invalidate];
- [timer release];
- timer = nil;
+ [self stopTimer];
[scrollView removeObserver:self forKeyPath:@"contentOffset"];
[scrollView removeObserver:self forKeyPath:@"contentSize"];
self.scrollView = nil;
Please sign in to comment.
Something went wrong with that request. Please try again.