关于如何在页面中使用EGORefreshTableHeaderView的文章网上一大把, 抄来抄去的, 但也都没什么大问题. 只是在XCode4.2的ARC环境中使用的时候, 错误一把. 借此机会, 完整的记录一下如何排除错误, 及使用的方法.
首先第一步当然是下载这个下拉更新的框架了. https://github.com/enormego/EGOTableViewPullRefresh/downloads
下载之后解包, 然后将
EGORefreshTableHeaderDelegate.h
EGORefreshTableHeaderDelegate.m
这两个文件, 以及项目中的图片文件都复制到你的项目文件内, 这时候, 如果你启用了ARC, 应该会报一片错误, 让我们来具体看一下.
启用了ARC之后, 就不允许手动的release了, 因此, [view release], [lable release] 还有 autorelease这样的代码都需要删除掉.
在EGORefreshTableHeaderDelegate.m的这个文件中, @synthesize delegate=_delegate; 会报错, "Existing ivar 'delegate' for assign property 'delegate' must be...
解决办法是需要将EGORefreshTableHeaderDelegate.h文件中的 assign 换为retain
//@property(nonatomic,assign) id <EGORefreshTableHeaderDelegate> delegate; //删除掉. 换为下面的 @property(nonatomic,retain)id <EGORefreshTableHeaderDelegate> delegate;
这样代码就会通过编译了~ 这样就需要将EGORefreshTableHeaderView与我们的tableview整合了, 然后按照Demo的方法,
添加EGORefreshTableHeaderDelegate的接口,
定义_reloading, 和EGORefreshHeaderView
声明reloadTableViewDataSource和doneLoadingTableView这两个函数
#import <UIKit/UIKit.h> #import "EGORefreshTableHeaderView.h" @interface FMFutureMessage : UIViewController<UITableViewDelegate, UITableViewDataSource,EGORefreshTableHeaderDelegate> { BOOL _reloading; EGORefreshTableHeaderView *_refreshHeaderView; } @property(strong, nonatomic) IBOutlet UITableView *tbView; -(void)reloadTableViewDataSource; -(void)doneLoadingTableViewData; @end
处理m文件, 建立关联.和响应事件.
- (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view from its nib. if(_refreshHeaderView == nil) { EGORefreshTableHeaderView *view = [[EGORefreshTableHeaderView alloc] initWithFrame:CGRectMake(0.0f, 0.0f - self.tbView.bounds.size.height, self.view.frame.size.width, self.tbView.bounds.size.height)]; view.delegate = self; [self.tbView addSubview:view]; _refreshHeaderView = view; } [_refreshHeaderView refreshLastUpdatedDate]; }
-(void)reloadTableViewDataSource { NSLog(@"==开始加载数据"); [self.tbView reloadData]; _reloading = YES; } - (void)doneLoadingTableViewData{ NSLog(@"===加载完数据"); // model should call this when its done loading _reloading = NO; [_refreshHeaderView egoRefreshScrollViewDataSourceDidFinishedLoading:self.tbView]; } #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 }
好了, 完成~~~