Latest 1.2.9
Homepage https://github.com/sofach/SFPullRefresh
License MIT
Platforms ios 5.0, requires ARC
Authors

SFPullRefresh (support ios5+)

SFPullRefresh provides a very simple way to implement pull refresh and load more, supports customizing refresh or loadmore control with your own view.

SFPullRefresh

Installation with CocoaPods


pod 'SFPullRefresh'

Usage

Basic

Add pull refresh handler and load more handler to your tableView or collectionView, and when you get data, you should call [self.table sf_finishLoading] to end loading animation, if there is no more data, you should call [self.table sf_reachEndWithText:@"reach end message"].

- (void)viewDidLoad
{
  ...
  __weak YourViewController *wkself = self; //you must use wkself to break the retain cycle
  [self.table sf_addRefreshHandler:^{
      wkself.page = 0;
      [wkself loadStrings];
  }];

  [self.table sf_addLoadMoreHandler:^{
      [wkself loadStrings];
  }];

  ...
}

- (void)loadStrings
{
    [self requestDataAtPage:self.page success:^(NSArray *strings) {
        if (self.table.sf_isRefreshing) {
            [self.items removeAllObjects];
        }
        [self.items addObjectsFromArray:strings];
        self.page++;
        if (strings.count<10) {
            [self.table sf_reachEndWithText:@"加载完毕"];
        }
        [self.table sf_finishLoading];

    } failure:^(NSString *msg) {
        [self.items removeAllObjects];
        [self.table sf_finishLoading];
    }];
}

Customization

You can customize refresh or load more control with your own view.


    CustomRefreshControl *customRefreshControl = [[CustomRefreshControl alloc] initWithFrame:CGRectMake(0, 0,  [UIScreen mainScreen].bounds.size.width, 60)];

    __weak YourViewController *wkself = self; //you must use wkself to break the retain cycle
    [self.table sf_addRefreshHandler:^{
        wkself.page = 0;
        [wkself loadStrings];
    } customRefreshControl:customRefreshControl];

The custom view must conforms to protocol SFRefreshControlDelegate or SFLoadMoreControlDelegate.

@protocol SFRefreshControlDelegate <NSObject>
- (void)willRefreshWithProgress:(CGFloat)progress;
- (void)beginRefreshing;
- (void)endRefreshing;

@optional
- (void)setTintColor:(UIColor *)tintColor;
@end

@protocol SFLoadMoreControlDelegate <NSObject>
- (void)beginLoading;
- (void)endLoading;
- (void)reachEndWithText:(NSString *)text;

@optional
- (void)setTintColor:(UIColor *)tintColor;
@end

Enjoy it!

Latest podspec

{
    "name": "SFPullRefresh",
    "version": "1.2.9",
    "summary": "add simple pull refresh to UITableView or UICollectionView",
    "description": "easy pull refresh for UITableView and UICollectionView, support custom refresh and loadmore control",
    "homepage": "https://github.com/sofach/SFPullRefresh",
    "license": "MIT",
    "authors": {
        "sofach": "[email protected]"
    },
    "platforms": {
        "ios": "5.0"
    },
    "source": {
        "git": "https://github.com/sofach/SFPullRefresh.git",
        "tag": "1.2.9"
    },
    "source_files": "SFPullRefresh/lib/**/*.{h,m}",
    "requires_arc": true
}

Pin It on Pinterest

Share This