All Products
Search
Document Center

Pull-down refresh component

Last Updated: May 25, 2021

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

API description

  • AUPullLoadingView.h

       
    1. //
    2. // EGORefreshTableHeaderView.h
    3. // Demo
    4. //
    5. #import <UIKit/UIKit.h>
    6. #import <QuartzCore/QuartzCore.h>
    7. typedef enum {
    8. AUEGOPullingDown = 1000,
    9. AUEGOPullingUp
    10. } AUEGOPullDirection;
    11. typedef enum{
    12. AUEGOOPullRefreshPulling = 0,
    13. AUEGOOPullRefreshNormal,
    14. AUEGOOPullRefreshLoading,
    15. } AUEGOPullRefreshState;
    16. @class AULoadingIndicatorView;
    17. @protocol AURefreshLoadingViewDelegate;
    18. /*!
    19. @class AURefreshLoadingView
    20. @abstract UIView
    21. @discussion This class is migrated from EGORefreshTableHeaderView. The class is used to load more views through pulling up or down.
    22. */
    23. @interface AUPullLoadingView : UIView {
    24. __weak id _delegate;
    25. AUEGOPullRefreshState _state;
    26. UILabel *_lastUpdatedLabel;
    27. UILabel *_statusLabel;
    28. // APActivityIndicatorView *_activityView;
    29. AUEGOPullDirection _pullDirection;
    30. BOOL isAutoPullFlag;
    31. }
    32. @property(nonatomic, strong) AULoadingIndicatorView *activityView;
    33. /**
    34. * 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.
    35. *
    36. * @param tip The tip text.
    37. *
    38. */
    39. - (void)setPullUp:(NSString *)tip;
    40. /**
    41. * 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.
    42. *
    43. * @param tip The tip text.
    44. *
    45. */
    46. - (void)setPullDown:(NSString *)tip;
    47. /**
    48. * Set the text for the loading process displayed after release. The default value is "Loading".
    49. * Note: The tip text is displayed in the loading process upon pull-up but not pull-down by default.
    50. *
    51. * @param tip The tip text.
    52. *
    53. */
    54. - (void)setLoading:(NSString *)tip;
    55. /**
    56. * The text displayed to prompt a user to release. The default value is "Release to refresh".
    57. *
    58. * @param tip The tip text.
    59. *
    60. */
    61. - (void)setRelease:(NSString *)tip;
    62. /**
    63. * Specify whether to display the text about the last update. The text is not displayed by default.
    64. *
    65. * @param isOpen If this parameter is set to YES, the text is displayed.
    66. *
    67. */
    68. - (void)ShowLastPullDate:(BOOL)isOpen;
    69. /**
    70. * Specify whether to display the text for the loading process.
    71. *
    72. * Default: No text is displayed upon pull-down refresh, and "Loading" is displayed upon pull-up-to-load.
    73. *
    74. * @param isShow If this parameter is set to YES, the text is displayed.
    75. *
    76. */
    77. - (void)ShowStatusLabel:(BOOL)isShow;
    78. - (void)setDateFormat:(NSDateFormatter *)dateFromatter;
    79. - (void)setAutoPull:(BOOL)isAutoPull;
    80. @property(nonatomic,weak) id <AURefreshLoadingViewDelegate> delegate;
    81. - (void)refreshLastUpdatedDate;
    82. - (void)egoRefreshScrollViewDidScroll:(UIScrollView *)scrollView;
    83. - (void)egoRefreshScrollViewDidEndDragging:(UIScrollView *)scrollView;
    84. - (void)egoRefreshScrollViewDataSourceDidFinishedLoading:(UIScrollView *)scrollView;
    85. - (void)egoRefreshScrollViewDataSourceDidFinishedLoadingWithoutUpdate:(UIScrollView *)scrollView;
    86. - (void)autoUpdateScrollView:(UIScrollView *)scrollView;
    87. #pragma Mark -- for LegacySystem not recommend
    88. @property(nonatomic,assign) AUEGOPullRefreshState state;
    89. @property(nonatomic,retain) NSString *statusText;
    90. @property (nonatomic, retain) UILabel *lastUpdatedLabel;
    91. @property (nonatomic, retain) UILabel *statusLabel;
    92. - (void)setCurrentDate;
    93. @end
    94. @protocol AURefreshLoadingViewDelegate
    95. - (void)egoRefreshTableHeaderDidTriggerRefresh:(AUPullLoadingView*)view;
    96. - (BOOL)egoRefreshTableHeaderDataSourceIsLoading:(AUPullLoadingView*)view;
    97. @optional
    98. - (NSDate*)egoRefreshTableHeaderDataSourceLastUpdated:(AUPullLoadingView*)view;
    99. @end
  • AUDragLoadingView.h

    For more information, see Drag loading view control.

Sample code

 
  1. //
  2. // APRefreshTableViewController.m
  3. // UIDemo
  4. //
  5. #import "APRefreshTableViewController.h"
  6. @interface APRefreshTableViewController ()
  7. {
  8. BOOL _headerReloading;
  9. BOOL _footerReloading;
  10. BOOL _isHeader;
  11. }
  12. @property(nonatomic,strong)AUPullLoadingView *refreshHeaderView;
  13. @property(nonatomic,strong)AUDragLoadingView *refreshFooterView;
  14. @property(nonatomic, strong) UITableView *tableView;
  15. @property(nonatomic, strong) NSMutableArray* listArray;
  16. @end
  17. @implementation APRefreshTableViewController
  18. - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
  19. {
  20. self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
  21. if (self) {
  22. // Custom initialization
  23. NSArray *array = @[@"0",
  24. @"1",
  25. @"2",
  26. @"3",
  27. @"4",
  28. @"5",
  29. @"6",
  30. @"7",
  31. @"8",
  32. @"9",
  33. @"10",
  34. @"11",
  35. @"12",
  36. @"13",
  37. @"14",
  38. @"15",
  39. @"16",
  40. @"17",
  41. @"18",
  42. @"19"];
  43. self.listArray = [NSMutableArray arrayWithArray:array];
  44. }
  45. return self;
  46. }
  47. - (void)viewDidLoad
  48. {
  49. [super viewDidLoad];
  50. // Do any additional setup after loading the view.
  51. self.edgesForExtendedLayout = UIRectEdgeNone;
  52. // self.navigationItem.rightBarButtonItem = [APUtil getBarButtonWithTitle:RightBarButtonTitle target:self];
  53. self.tableView = [[UITableView alloc]initWithFrame:self.view.bounds style:UITableViewStylePlain];
  54. self.tableView.dataSource = self;
  55. self.tableView.delegate = self;
  56. self.tableView.backgroundColor = [UIColor colorWithRGB:0xf5f5f9];
  57. self.tableView.separatorColor = [UIColor colorWithRGB:0xdddddd];
  58. [self.view addSubview:self.tableView];
  59. if (_refreshHeaderView == nil) {
  60. 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)];
  61. view.delegate = self;
  62. [view ShowLastPullDate:YES];
  63. [view ShowStatusLabel:NO];
  64. [self.tableView addSubview:view];
  65. _refreshHeaderView = view;
  66. }
  67. [_refreshHeaderView refreshLastUpdatedDate];
  68. if (_refreshFooterView == nil) {
  69. AUDragLoadingView *view = [[AUDragLoadingView alloc] initWithFrame:CGRectMake(0, 0, self.view.bounds.size.width, 48)];
  70. view.delegate = self;
  71. [view setPullUp:@"上拉加载更多信息"];
  72. [view setRelease:@"放松"];
  73. self.tableView.tableFooterView = view;
  74. _refreshFooterView = view;
  75. }
  76. _isHeader = YES;
  77. }
  78. - (void)didReceiveMemoryWarning
  79. {
  80. [super didReceiveMemoryWarning];
  81. // Dispose of any resources that can be recreated.
  82. }
  83. #pragma tableview datasource
  84. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
  85. {
  86. return 1;
  87. }
  88. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
  89. {
  90. return _listArray.count;
  91. }
  92. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
  93. {
  94. static NSString *CellIdentifier = @"RefreshCell";
  95. UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
  96. if (nil == cell)
  97. {
  98. cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault
  99. reuseIdentifier:CellIdentifier];
  100. }
  101. cell.textLabel.text = _listArray[indexPath.row];
  102. cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
  103. return cell;
  104. }
  105. #pragma mark -
  106. #pragma mark Data Source Loading / Reloading Methods
  107. - (void)reloadHeaderTableViewDataSource{
  108. // should be calling your tableviews data source model to reload
  109. // put here just for demo
  110. NSInteger first = [_listArray[0] integerValue] - 1;
  111. [_listArray insertObject:[NSString stringWithFormat:@"%li",(long)first] atIndex:0];
  112. _headerReloading = YES;
  113. }
  114. - (void)doneLoadingHeaderTableViewData{
  115. // model should call this when its done loading
  116. _headerReloading = NO;
  117. [_refreshHeaderView egoRefreshScrollViewDataSourceDidFinishedLoading:self.tableView];
  118. [self.tableView reloadData];
  119. }
  120. - (void)reloadFooterTableViewDataSource{
  121. // should be calling your tableviews data source model to reload
  122. // put here just for demo
  123. NSInteger count = [_listArray count];
  124. NSInteger last = [_listArray[count-1] integerValue] + 1;
  125. [_listArray addObject:[NSString stringWithFormat:@"%li",(long)last]];
  126. _footerReloading = YES;
  127. }
  128. - (void)doneLoadingFooterTableViewData{
  129. // model should call this when its done loading
  130. _footerReloading = NO;
  131. [_refreshFooterView egoRefreshScrollViewDataSourceDidFinishedLoading:self.tableView];
  132. [self.tableView reloadData];
  133. }
  134. #pragma mark -
  135. #pragma mark UIScrollViewDelegate Methods
  136. - (void)scrollViewDidScroll:(UIScrollView *)scrollView
  137. {
  138. if (scrollView.contentInset.top + scrollView.contentOffset.y < 0) {
  139. _isHeader = YES;
  140. } else {
  141. _isHeader = NO;
  142. }
  143. if (_isHeader) {
  144. [_refreshHeaderView egoRefreshScrollViewDidScroll:scrollView];
  145. } else {
  146. [_refreshFooterView egoRefreshScrollViewDidScroll:scrollView];
  147. }
  148. }
  149. - (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate
  150. {
  151. if (_isHeader) {
  152. [_refreshHeaderView egoRefreshScrollViewDidEndDragging:scrollView];
  153. } else {
  154. [_refreshFooterView egoRefreshScrollViewDidEndDragging:scrollView];
  155. }
  156. }
  157. #pragma mark -
  158. #pragma mark EGORefreshTableHeaderDelegate Methods
  159. - (void)egoRefreshTableHeaderDidTriggerRefresh:(AUPullLoadingView*)view
  160. {
  161. if (_isHeader) {
  162. [self reloadHeaderTableViewDataSource];
  163. [self performSelector:@selector(doneLoadingHeaderTableViewData) withObject:nil afterDelay:2.0];
  164. } else {
  165. [self reloadFooterTableViewDataSource];
  166. [self performSelector:@selector(doneLoadingFooterTableViewData) withObject:nil afterDelay:2.0];
  167. }
  168. }
  169. - (BOOL)egoRefreshTableHeaderDataSourceIsLoading:(AUPullLoadingView*)view
  170. {
  171. if (_isHeader) {
  172. return _headerReloading;
  173. } else {
  174. return _footerReloading; // should return if data source model is reloading
  175. }
  176. }
  177. - (NSDate*)egoRefreshTableHeaderDataSourceLastUpdated:(AUPullLoadingView*)view{
  178. return [NSDate date]; // should return date data source was last changed
  179. }
  180. @end