UITableview添加下拉刷新

实现的开源框架是:https://github.com/enormego/EGOTableViewPullRefresh

使用方法:

1.添加QuartzCore.framework

2.拷贝框架内的素材,也就是所有的图片,箭头什么的

3.引入demo中EGORefreshTableHeaderView.h和EGORefreshTableHeaderView.m

然后就可以添加代码了,在tableview的.h文件中:

#import <UIKit/UIKit.h>

#import “EGORefreshTableHeaderView.h”

@interface MessageTableViewController : UIViewController<UITableViewDataSource,UITableViewDelegate,EGORefreshTableHeaderDelegate>

{

IBOutlet UITableView *innerTable;

EGORefreshTableHeaderView *_refreshHeaderView;

BOOL _reloading;

}

– (void)reloadTableViewDataSource;

– (void)doneLoadingTableViewData;

@end

然后是.m文件:

除了Tableview必须有的函数外,要添加下面代码:

– (void)viewDidLoad

{

[super viewDidLoad];

if (_refreshHeaderView == nil) {

EGORefreshTableHeaderView *view1 = [[EGORefreshTableHeaderView alloc] initWithFrame:CGRectMake(0.0f, 10.0f – innerTable.bounds.size.height, innerTable.frame.size.width, self.view.bounds.size.height)];

view1.delegate = self;

[innerTable addSubview:view1];

_refreshHeaderView = view1;

[view1 release];

}

[_refreshHeaderView refreshLastUpdatedDate];

}

#pragma mark –

#pragma mark Data Source Loading / Reloading Methods

– (void)reloadTableViewDataSource{

NSLog(@”==开始加载数据”);

// NSLog(@”1111″);

_reloading = YES;

}

– (void)doneLoadingTableViewData{

NSLog(@”===加载完数据”);

_reloading = NO;

// NSLog(@”2222″);

[_refreshHeaderView egoRefreshScrollViewDataSourceDidFinishedLoading:innerTable];

}

#pragma mark –

#pragma mark UIScrollViewDelegate Methods

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

// NSLog(@”3333″);

[_refreshHeaderView egoRefreshScrollViewDidScroll:scrollView];

}

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

// NSLog(@”4444″);

[_refreshHeaderView egoRefreshScrollViewDidEndDragging:scrollView];

}

#pragma mark –

#pragma mark EGORefreshTableHeaderDelegate Methods

//确实开始刷新

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

NSLog(@”5555″);

[self reloadTableViewDataSource];

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

}

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

// NSLog(@”6666″);

return _reloading;

}

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

// NSLog(@”7777″);

return [NSDate date];

}

发表评论

电子邮件地址不会被公开。 必填项已用*标注