All Products
Search
Document Center

Mobile Platform as a Service:Pull-down refresh component

Last Updated:Mar 08, 2022

The AUDragLoadingView and the Aupullloadingview provide the loading style when the page is pulled up or down.

The following controls are not customized for businesses and must be switched to the AUPullLoadingView or AUDragLoadingView control.

CommonUI: ODRefreshControl, APCircleRefreshControl, EGORefreshTableHeaderView, and APNextPagePullView.

Sample image

Pull-down refresh component

API description

  • 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    This class is migrated from EGORefreshTableHeaderView. The class is used to load more views through pulling up or down.
       */
    
      @interface AUPullLoadingView : UIView {
    
          __weak id _delegate;
          AUEGOPullRefreshState _state;
    
          UILabel *_lastUpdatedLabel;
          UILabel *_statusLabel;
      //    APActivityIndicatorView *_activityView;
          AUEGOPullDirection _pullDirection;
    
          BOOL    isAutoPullFlag;
      }
      @property(nonatomic, strong) AULoadingIndicatorView *activityView;
    
      /**
       *  Set the text for pull-up-to-load in initial state. The default value is "Pull up to load more", which is displayed upon pull-up.
       *
       *  @param tip The tip text.
       *
       */
      - (void)setPullUp:(NSString *)tip;
    
      /**
       *  Set the text for pull-down fresh in initial state. The default value is "Pull down to refresh", which is not displayed upon pull-down.
       *
       *  @param tip The tip text.
       *
       */
      - (void)setPullDown:(NSString *)tip;
    
      /**
       *  Set the text for the loading process displayed after release. The default value is "Loading".
       *  Note: The tip text is displayed in the loading process upon pull-up but not pull-down by default.
       *
       *  @param tip The tip text.
       *
       */
      - (void)setLoading:(NSString *)tip;
    
      /**
       *  The text displayed to prompt a user to release. The default value is "Release to refresh".
       *
       *  @param tip The tip text.
       *
       */
      - (void)setRelease:(NSString *)tip;
    
      /**
       *  Specify whether to display the text about the last update. The text is not displayed by default.
       *
       *  @param isOpen If this parameter is set to YES, the text is displayed.
       *
       */
      - (void)ShowLastPullDate:(BOOL)isOpen;
    
      /**
       *  Specify whether to display the text for the loading process.
       *  
       *  Default: No text is displayed upon pull-down refresh, and "Loading" is displayed upon pull-up-to-load.
       *
       *  @param isShow If this parameter is set to YES, the text is displayed.
       *
       */
      - (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;
      @end
  • AUDragLoadingView.h

    For more information, see Drag loading view control.

Sample code

//
//  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"];
        [view setRelease:@"Relax"];
        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