Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added refreshEnabledProperty which allows to disable/enable refresh manually #13

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Classes/PullRefreshTableViewController.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
NSString *textPull;
NSString *textRelease;
NSString *textLoading;
BOOL refreshEnabled;
}

@property (nonatomic, retain) UIView *refreshHeaderView;
Expand All @@ -49,6 +50,7 @@
@property (nonatomic, copy) NSString *textPull;
@property (nonatomic, copy) NSString *textRelease;
@property (nonatomic, copy) NSString *textLoading;
@property (nonatomic, assign) BOOL refreshEnabled;

- (void)setupStrings;
- (void)addPullToRefreshHeader;
Expand Down
13 changes: 10 additions & 3 deletions Classes/PullRefreshTableViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@

@implementation PullRefreshTableViewController

@synthesize textPull, textRelease, textLoading, refreshHeaderView, refreshLabel, refreshArrow, refreshSpinner;
@synthesize textPull, textRelease, textLoading, refreshHeaderView, refreshLabel, refreshArrow, refreshSpinner, refreshEnabled;

- (id)initWithStyle:(UITableViewStyle)style {
self = [super initWithStyle:style];
Expand Down Expand Up @@ -70,6 +70,7 @@ - (void)setupStrings{
textPull = [[NSString alloc] initWithString:@"Pull down to refresh..."];
textRelease = [[NSString alloc] initWithString:@"Release to refresh..."];
textLoading = [[NSString alloc] initWithString:@"Loading..."];
refreshEnabled = YES;
}

- (void)addPullToRefreshHeader {
Expand All @@ -93,6 +94,7 @@ - (void)addPullToRefreshHeader {
[refreshHeaderView addSubview:refreshLabel];
[refreshHeaderView addSubview:refreshArrow];
[refreshHeaderView addSubview:refreshSpinner];
refreshHeaderView.hidden = !refreshEnabled;
[self.tableView addSubview:refreshHeaderView];
}

Expand All @@ -108,7 +110,7 @@ - (void)scrollViewDidScroll:(UIScrollView *)scrollView {
self.tableView.contentInset = UIEdgeInsetsZero;
else if (scrollView.contentOffset.y >= -REFRESH_HEADER_HEIGHT)
self.tableView.contentInset = UIEdgeInsetsMake(-scrollView.contentOffset.y, 0, 0, 0);
} else if (isDragging && scrollView.contentOffset.y < 0) {
} else if (refreshEnabled && isDragging && scrollView.contentOffset.y < 0) {
// Update the arrow direction and label
[UIView beginAnimations:nil context:NULL];
if (scrollView.contentOffset.y < -REFRESH_HEADER_HEIGHT) {
Expand All @@ -126,7 +128,7 @@ - (void)scrollViewDidScroll:(UIScrollView *)scrollView {
- (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate {
if (isLoading) return;
isDragging = NO;
if (scrollView.contentOffset.y <= -REFRESH_HEADER_HEIGHT) {
if (refreshEnabled && scrollView.contentOffset.y <= -REFRESH_HEADER_HEIGHT) {
// Released above the header
[self startLoading];
}
Expand Down Expand Up @@ -168,6 +170,11 @@ - (void)stopLoadingComplete:(NSString *)animationID finished:(NSNumber *)finishe
[refreshSpinner stopAnimating];
}

-(void)setRefreshEnabled:(BOOL)enabled{
refreshEnabled = enabled;
refreshHeaderView.hidden = !enabled;
}

- (void)refresh {
// This is just a demo. Override this method with your custom reload action.
// Don't forget to call stopLoading at the end.
Expand Down