ios下拉刷新笔记

一、找到你的 UITableView / 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二、切换到你的 UITableView / UITableViewController 的 .m 文件,结合以下代码,添加相应的元素: -(void)viewDidLoad {
[super viewDidLoad];

if(_refreshHeaderView ==nil){

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)];
view.delegate = self;
[self.tableView addSubview:view];
_refreshHeaderView = view;
[view release];

}

//  update the last update date
[_refreshHeaderView refreshLastUpdatedDate];
}

#pragma mark -
#pragma mark Data Source Loading / Reloading Methods

-(void)reloadTableViewDataSource{

//  should be calling your tableviews data source model to reload
//  put here just for demo
_reloading =YES;

}

-(void)doneLoadingTableViewData{

//  model should call this when its done loading
_reloading =NO;
[_refreshHeaderView egoRefreshScrollViewDataSourceDidFinishedLoading:self.tableView];

}

#pragma mark -
#pragma mark UIScrollViewDelegate Methods

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

[_refreshHeaderView egoRefreshScrollViewDidScroll:scrollView];

}

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

[_refreshHeaderView egoRefreshScrollViewDidEndDragging:scrollView];

}

#pragma mark -
#pragma mark EGORefreshTableHeaderDelegate Methods

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

[self reloadTableViewDataSource];
[self performSelector:@selector(doneLoadingTableViewData) withObject:nil afterDelay:3.0];

}

-(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

}三、最后呢,为了彰显你良好的内存管理习惯,别忘了释放掉相应的 UI 元素:

-(void)viewDidUnload {
_refreshHeaderView=nil;
}

-(void)dealloc {

_refreshHeaderView =nil;
[super dealloc];
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值