废话不多说,直接上传代码说明

1.把EGORefreshTableHeaderView.h和EGORefreshTableHeaderView.m文件拉入到工程

2.viewcontroller文件添加引用#import "EGORefreshTableHeaderView.h"和协议<</span>EGORefreshTableHeaderDelegate>

3.定义对象


EGORefreshTableHeaderView *refreshView;

    BOOL reloading;


//注意reloading是必须的


4 实现delegate

#pragma mark - EGORefreshTableHeaderDelegate Methods

//下拉控件刷新触发事件

- (void)egoRefreshTableHeaderDidTriggerRefresh:(EGORefreshTableHeaderView*)view{

[self reloadTableViewDataSource];

}


- (BOOL)egoRefreshTableHeaderDataSourceIsLoading:(EGORefreshTableHeaderView*)view{

return reloading; // should return if data source model is reloading

}


- (NSDate*)egoRefreshTableHeaderDataSourceLastUpdated:(EGORefreshTableHeaderView*)view{

return [NSDate date]; // should return date data source was last changed

}


#pragma mark - UIScrollViewDelegate Methods

- (void)scrollViewDidScroll:(UIScrollView *)scrollView{

[refreshView egoRefreshScrollViewDidScroll:scrollView];

}


- (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate{

[refreshView egoRefreshScrollViewDidEndDragging:scrollView];

 

}


注意要实现UIScrollViewDelegate


5 添加load数据的函数和load完数据的函数


#pragma mark Data Source Loading / Reloading Methods

//下拉动作触发事件调用的函数。在这里发送数据请求

- (void)reloadTableViewDataSource{

 

//  should be calling your tableviews data source model to reload

//  put here just for demo

    NSLog(@"dragging!!!");

    timer = [NSTimer scheduledTimerWithTimeInterval:5 target:selfselector:@selector(doneLoadingTableViewData) userInfo:nil repeats:NO];

reloading = YES;

 

}

//请求结束函数。在这里要关闭下拉的视图.并更新表视图

- (void)doneLoadingTableViewData{

 

//  model should call this when its done loading

    NSLog(@"stop loading");

    timer = nil;

reloading = NO;

[refreshView egoRefreshScrollViewDataSourceDidFinishedLoading:self.tableView];


    [listData addObject:[[NSString alloc] initWithFormat:@"%d",[listData count]]];

 

    [self.tableView reloadData];

 

}