首页 > 代码库 > IOS控件 Tableview 下拉刷新,加载数据

IOS控件 Tableview 下拉刷新,加载数据

 

一、 点击此连链接下载资源文件,将EGORefreshTableHeaderView.hEGORefreshTableHeaderView.m两个文件,以及Enormego提供的那一套图片包拖进你的工程里。

二、找到你的  UITableViewController 的 .h 文件,添加相应的代码:

#import "EGORefreshTableHeaderView.h"    @interface RootViewController : UITableViewController  {    EGORefreshTableHeaderView *_refreshHeaderView;    //  Reloading var should really be your tableviews datasource  //  Putting it here for demo purposes  BOOL _reloading;  }    - (void)reloadTableViewDataSource;  - (void)doneLoadingTableViewData;  @end  


三、切换到你的  UITableViewController 的 .m 文件,添加相应的代码:

  

 1 - (void)viewDidLoad {   2 [super viewDidLoad];   3    4 if (_refreshHeaderView == nil) {   5    6 EGORefreshTableHeaderView *view = [[EGORefreshTableHeaderView alloc] initWithFrame:CGRectMake(0.0f, 0.0f - self.tableView.bounds.size.height, self.view.frame.size.width, self.tableView.bounds.size.height)];   7 view.delegate = self;   8 [self.tableView addSubview:view];   9 _refreshHeaderView = view;  10 [view release];  11   12 }  13   14 //  update the last update date  15 [_refreshHeaderView refreshLastUpdatedDate];  16 }  

 

 1 #pragma mark -   2 #pragma mark Data Source Loading / Reloading Methods   3    4 - (void)reloadTableViewDataSource{   5    6 //  should be calling your tableviews data source model to reload   7 //  put here just for demo   8 _reloading = YES;   9   10 }  11   12 - (void)doneLoadingTableViewData{  13   14 //  model should call this when its done loading  15 _reloading = NO;  16 [_refreshHeaderView egoRefreshScrollViewDataSourceDidFinishedLoading:self.tableView];  17   18 }  19   20 #pragma mark -  21 #pragma mark UIScrollViewDelegate Methods  22   23 - (void)scrollViewDidScroll:(UIScrollView *)scrollView{  24   25 [_refreshHeaderView egoRefreshScrollViewDidScroll:scrollView];  26   27 }  28   29 - (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate{  30   31 [_refreshHeaderView egoRefreshScrollViewDidEndDragging:scrollView];  32   33 }  34   35 #pragma mark -  36 #pragma mark EGORefreshTableHeaderDelegate Methods  37   38 - (void)egoRefreshTableHeaderDidTriggerRefresh:(EGORefreshTableHeaderView*)view{  39   40 [self reloadTableViewDataSource];  41 [self performSelector:@selector(doneLoadingTableViewData) withObject:nil afterDelay:3.0];  42   43 }  44   45 - (BOOL)egoRefreshTableHeaderDataSourceIsLoading:(EGORefreshTableHeaderView*)view{  46   47 return _reloading; // should return if data source model is reloading  48   49 }  50   51 - (NSDate*)egoRefreshTableHeaderDataSourceLastUpdated:(EGORefreshTableHeaderView*)view{  52   53 return [NSDate date]; // should return date data source was last changed  54   55 }  

 

 

四、最后呢,别忘了内存管理习惯,如果是ARC管理则可以不用dealloc。如果是MRC的话,就把下面的那个全部内存释放写上:

 

1 - (void)viewDidUnload {  2 _refreshHeaderView=nil;  3 }  4   5 - (void)dealloc {  6   7 _refreshHeaderView = nil;  8 [super dealloc];  9 }  

PS:转自他人分享。。

IOS控件 Tableview 下拉刷新,加载数据