The pull-up refresh component (AUDragLoadingView) and the pull-down refresh component (AUPullLoadingView) provide loading styles when pulling up or down on a page.
You can replace all non-customized controls with the pull-down (AUPullLoadingView) or pull-up (AUDragLoadingView) components.
CommonUI includes four components: ODRefreshControl, APCircleRefreshControl, EGORefreshTableHeaderView, and APNextPagePullView.
API reference
AUPullLoadingView.h
// // EGORefreshTableHeaderView.h // Demo // #import <UIKit/UIKit.h> #import <QuartzCore/QuartzCore.h> typedef enum { AUEGOPullingDown = 1000, AUEGOPullingUp } AUEGOPullDirection; typedef enum{ AUEGOOPullRefreshPulling = 0, AUEGOOPullRefreshNormal, AUEGOOPullRefreshLoading, } AUEGOPullRefreshState; @class AULoadingIndicatorView; @protocol AURefreshLoadingViewDelegate; /*! @class AURefreshLoadingView @abstract UIView @discussion Migrated from the third-party EGORefreshTableHeaderView. A view that supports pull-down-to-refresh and pull-up-to-load-more features. */ @interface AUPullLoadingView : UIView { __weak id _delegate; AUEGOPullRefreshState _state; UILabel *_lastUpdatedLabel; UILabel *_statusLabel; // APActivityIndicatorView *_activityView; AUEGOPullDirection _pullDirection; BOOL isAutoPullFlag; } @property(nonatomic, strong) AULoadingIndicatorView *activityView; /** * Sets the initial status text for pull-up-to-load. The default text is "Pull up to load more". This text is displayed by default. * * @param tip The content of the tip. * */ - (void)setPullUp:(NSString *)tip; /** * Sets the initial status text for pull-down-to-refresh. The default text is "Pull down to refresh". This text is not displayed by default. * * @param tip The content of the tip. * */ - (void)setPullDown:(NSString *)tip; /** * Sets the text displayed during the loading process after you release the control. The default text is "Loading...". * Note: This text is not displayed for pull-down-to-refresh by default, but it is displayed for pull-up-to-load. * * @param tip The content of the tip. * */ - (void)setLoading:(NSString *)tip; /** * Sets the text that prompts the user to release the control. The default text is "Release to refresh". * * @param tip The content of the tip. * */ - (void)setRelease:(NSString *)tip; /** * Specifies whether to display the text for the last refresh time. This text is not displayed by default. * * @param isOpen Set to YES to display the text. * */ - (void)ShowLastPullDate:(BOOL)isOpen; /** * Specifies whether to display the loading status text. * * Default: The text is not displayed for pull-down-to-refresh, but the text "Loading..." is displayed for pull-up-to-load. * * @param isShow Set to YES to display the text. * */ - (void)ShowStatusLabel:(BOOL)isShow; - (void)setDateFormat:(NSDateFormatter *)dateFromatter; - (void)setAutoPull:(BOOL)isAutoPull; @property(nonatomic,weak) id <AURefreshLoadingViewDelegate> delegate; - (void)refreshLastUpdatedDate; - (void)egoRefreshScrollViewDidScroll:(UIScrollView *)scrollView; - (void)egoRefreshScrollViewDidEndDragging:(UIScrollView *)scrollView; - (void)egoRefreshScrollViewDataSourceDidFinishedLoading:(UIScrollView *)scrollView; - (void)egoRefreshScrollViewDataSourceDidFinishedLoadingWithoutUpdate:(UIScrollView *)scrollView; - (void)autoUpdateScrollView:(UIScrollView *)scrollView; #pragma Mark -- for LegacySystem not recommend @property(nonatomic,assign) AUEGOPullRefreshState state; @property(nonatomic,retain) NSString *statusText; @property (nonatomic, retain) UILabel *lastUpdatedLabel; @property (nonatomic, retain) UILabel *statusLabel; - (void)setCurrentDate; @end @protocol AURefreshLoadingViewDelegate - (void)egoRefreshTableHeaderDidTriggerRefresh:(AUPullLoadingView*)view; - (BOOL)egoRefreshTableHeaderDataSourceIsLoading:(AUPullLoadingView*)view; @optional - (NSDate*)egoRefreshTableHeaderDataSourceLastUpdated:(AUPullLoadingView*)view; @endAUDragLoadingView.h
For more information, see pull-up refresh control.
Code example
//
// APRefreshTableViewController.m
// UIDemo
//
#import "APRefreshTableViewController.h"
@interface APRefreshTableViewController ()
{
BOOL _headerReloading;
BOOL _footerReloading;
BOOL _isHeader;
}
@property(nonatomic,strong)AUPullLoadingView *refreshHeaderView;
@property(nonatomic,strong)AUDragLoadingView *refreshFooterView;
@property(nonatomic, strong) UITableView *tableView;
@property(nonatomic, strong) NSMutableArray* listArray;
@end
@implementation APRefreshTableViewController
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
NSArray *array = @[@"0",
@"1",
@"2",
@"3",
@"4",
@"5",
@"6",
@"7",
@"8",
@"9",
@"10",
@"11",
@"12",
@"13",
@"14",
@"15",
@"16",
@"17",
@"18",
@"19"];
self.listArray = [NSMutableArray arrayWithArray:array];
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
self.edgesForExtendedLayout = UIRectEdgeNone;
// self.navigationItem.rightBarButtonItem = [APUtil getBarButtonWithTitle:RightBarButtonTitle target:self];
self.tableView = [[UITableView alloc]initWithFrame:self.view.bounds style:UITableViewStylePlain];
self.tableView.dataSource = self;
self.tableView.delegate = self;
self.tableView.backgroundColor = [UIColor colorWithRGB:0xf5f5f9];
self.tableView.separatorColor = [UIColor colorWithRGB:0xdddddd];
[self.view addSubview:self.tableView];
if (_refreshHeaderView == nil) {
AUPullLoadingView *view = [[AUPullLoadingView alloc] initWithFrame:CGRectMake(0.0f, 0.0f - self.tableView.bounds.size.height, self.view.frame.size.width, self.tableView.bounds.size.height)];
view.delegate = self;
[view ShowLastPullDate:YES];
[view ShowStatusLabel:NO];
[self.tableView addSubview:view];
_refreshHeaderView = view;
}
[_refreshHeaderView refreshLastUpdatedDate];
if (_refreshFooterView == nil) {
AUDragLoadingView *view = [[AUDragLoadingView alloc] initWithFrame:CGRectMake(0, 0, self.view.bounds.size.width, 48)];
view.delegate = self;
[view setPullUp:@"Pull up to load more information"];
[view setRelease:@"Release"];
self.tableView.tableFooterView = view;
_refreshFooterView = view;
}
_isHeader = YES;
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
#pragma tableview datasource
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return _listArray.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"RefreshCell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (nil == cell)
{
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault
reuseIdentifier:CellIdentifier];
}
cell.textLabel.text = _listArray[indexPath.row];
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
return cell;
}
#pragma mark -
#pragma mark Data Source Loading / Reloading Methods
- (void)reloadHeaderTableViewDataSource{
// should be calling your tableviews data source model to reload
// put here just for demo
NSInteger first = [_listArray[0] integerValue] - 1;
[_listArray insertObject:[NSString stringWithFormat:@"%li",(long)first] atIndex:0];
_headerReloading = YES;
}
- (void)doneLoadingHeaderTableViewData{
// model should call this when its done loading
_headerReloading = NO;
[_refreshHeaderView egoRefreshScrollViewDataSourceDidFinishedLoading:self.tableView];
[self.tableView reloadData];
}
- (void)reloadFooterTableViewDataSource{
// should be calling your tableviews data source model to reload
// put here just for demo
NSInteger count = [_listArray count];
NSInteger last = [_listArray[count-1] integerValue] + 1;
[_listArray addObject:[NSString stringWithFormat:@"%li",(long)last]];
_footerReloading = YES;
}
- (void)doneLoadingFooterTableViewData{
// model should call this when its done loading
_footerReloading = NO;
[_refreshFooterView egoRefreshScrollViewDataSourceDidFinishedLoading:self.tableView];
[self.tableView reloadData];
}
#pragma mark -
#pragma mark UIScrollViewDelegate Methods
- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
if (scrollView.contentInset.top + scrollView.contentOffset.y < 0) {
_isHeader = YES;
} else {
_isHeader = NO;
}
if (_isHeader) {
[_refreshHeaderView egoRefreshScrollViewDidScroll:scrollView];
} else {
[_refreshFooterView egoRefreshScrollViewDidScroll:scrollView];
}
}
- (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate
{
if (_isHeader) {
[_refreshHeaderView egoRefreshScrollViewDidEndDragging:scrollView];
} else {
[_refreshFooterView egoRefreshScrollViewDidEndDragging:scrollView];
}
}
#pragma mark -
#pragma mark EGORefreshTableHeaderDelegate Methods
- (void)egoRefreshTableHeaderDidTriggerRefresh:(AUPullLoadingView*)view
{
if (_isHeader) {
[self reloadHeaderTableViewDataSource];
[self performSelector:@selector(doneLoadingHeaderTableViewData) withObject:nil afterDelay:2.0];
} else {
[self reloadFooterTableViewDataSource];
[self performSelector:@selector(doneLoadingFooterTableViewData) withObject:nil afterDelay:2.0];
}
}
- (BOOL)egoRefreshTableHeaderDataSourceIsLoading:(AUPullLoadingView*)view
{
if (_isHeader) {
return _headerReloading;
} else {
return _footerReloading; // should return if data source model is reloading
}
}
- (NSDate*)egoRefreshTableHeaderDataSourceLastUpdated:(AUPullLoadingView*)view{
return [NSDate date]; // should return date data source was last changed
}
@end