到http://pan.baidu.com/s/1pJ4nadX下载DEMO
上拉下拉刷新终结版---你需要替换的地方在如下三个函数,具体为红色粗体部分。
/**
* 加载数据源(通常是你的异步操作)
*
* @param aRefreshPo 载入/加载位置
*/
- (void)reloadTableViewDataSource
{
switch (self.refreshPos) {
caseEGORefreshHeader:
[self performSelector:@selector(doneLoadingTableViewData) withObject:nil afterDelay:3.0];
break;
caseEGORefreshFooter:
[self performSelector:@selector(doneLoadingTableViewData) withObject:nil afterDelay:3.0];
break;
default:
break;
}
}
/**
* 完成加载
*/
- (void)doneLoadingTableViewData
{
int count = [self.mutableArray count];
for (int i = 0; i < 3; i++) {
[self.mutableArray addObject:[NSString stringWithFormat:@"%d", count + i]];
}
[self.myTableView reloadData];
if (self.refreshHeaderView &&self.refreshPos ==EGORefreshHeader) {
[self.refreshHeaderViewegoRefreshScrollViewDataSourceDidFinishedLoading:self.myTableView];
[selfsetFooterView];
}
if (self.refreshFooterView &&self.refreshPos ==EGORefreshFooter) {
[self.refreshFooterViewegoRefreshScrollViewDataSourceDidFinishedLoading:self.myTableView];
[selfsetFooterView];
}
self.reloading =NO;
self.refreshPos =EGORefreshNone;
}
/**
* 自动下拉刷新
*
* @param animated
*/
-(void)showRefreshHeader:(BOOL)animated
{
if (animated)
{
[UIViewbeginAnimations:nilcontext:NULL];
[UIViewsetAnimationDuration:0.2];
self.myTableView.contentInset =UIEdgeInsetsMake(60.0f,0.0f, 0.0f,0.0f);// set the Inset
[UIViewcommitAnimations];
}
else
{
self.myTableView.contentInset =UIEdgeInsetsMake(60.0f,0.0f, 0.0f,0.0f);
[self.myTableViewscrollRectToVisible:CGRectMake(0,0.0f, 1, 1)animated:NO];
}
if (self.refreshHeaderView) {
[self.refreshHeaderViewsetState:EGOOPullRefreshLoading];
}
//你的异步操作
self.refreshPos =EGORefreshHeader;
[self performSelector:@selector(doneLoadingTableViewData) withObject:nil afterDelay:3.0];
}