文档

下拉刷新控件

更新时间:

上拉刷新组件(AUDragLoadingView)和下拉刷新组件(Aupullloadingview)提供上拉或下拉页面时的加载样式。

以下非业务定制化的控件,都需要切换为下拉(AUPullLoadingView)或上拉(AUDragLoadingView)组件。

CommonUI 包含 ODRefreshControl、APCircleRefreshControl、EGORefreshTableHeaderView、APNextPagePullView 四个组件。

效果图

接口说明

  • 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  从第三方 EGORefreshTableHeaderView 迁移而来,功能下拉、上拉加载更多的 view
       */
    
      @interface AUPullLoadingView : UIView {
    
          __weak id _delegate;
          AUEGOPullRefreshState _state;
    
          UILabel *_lastUpdatedLabel;
          UILabel *_statusLabel;
      //    APActivityIndicatorView *_activityView;
          AUEGOPullDirection _pullDirection;
    
          BOOL    isAutoPullFlag;
      }
      @property(nonatomic, strong) AULoadingIndicatorView *activityView;
    
      /**
       *  上拉加载时,设置初始状态文案信息,默认为“上拉加载更多”,显示
       *
       *  @param tip tips 内容
       *
       */
      - (void)setPullUp:(NSString *)tip;
    
      /**
       *  下拉刷新时,设置初始状态文案信息,默认为“下拉刷新”。不显示
       *
       *  @param tip tips 内容
       *
       */
      - (void)setPullDown:(NSString *)tip;
    
      /**
       *  设置松手后 loading 过程中的文案信息,默认为“加载中”。
       *  注意:默认下拉刷新时不显示,上拉加载时显示
       *
       *  @param tip tips 内容
       *
       */
      - (void)setLoading:(NSString *)tip;
    
      /**
       *  提示用户可以放手的文案信息,默认为“释放即可刷新”
       *
       *  @param tip tips 内容
       *
       */
      - (void)setRelease:(NSString *)tip;
    
      /**
       *  是否显示上次刷新信息的文案,默认不显示
       *
       *  @param isOpen YES 表示显示
       *
       */
      - (void)ShowLastPullDate:(BOOL)isOpen;
    
      /**
       *  是否显示加载状态信息的文案。
       *  
       *  默认:下拉刷新时不显示,上拉加载时,显示文案“加载中”
       *
       *  @param isShow YES 表示显示
       *
       */
      - (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

    详情请参见 上拉刷新控件

代码示例

//
//  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:@"上拉加载更多信息"];
        [view setRelease:@"放松"];
        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
  • 本页导读 (0)
文档反馈