方便使用上拉刷新和加载更多
首先,通过CYPullRefresh实现上拉刷新和加载更多功能非常简单。只需导入UIScrollView+CYPullRefresh分类。通过两行代码进行初始化。
- (void)cy_addPullDownHanlder:(CYPullRefreshBlock)handler topView:(UIView<CYPullRefreshViewProtocol> *)topView;
- (void)cy_addPullUpHandler:(CYPullRefreshBlock)handler bottomView:(UIView<CYPullRefreshViewProtocol> *)bottomView;
查看示例项目
CYPullRefreshSimpleBottomView *bottomView = [[CYPullRefreshSimpleBottomView alloc] init];
CYPullRefreshSimpleTopView *topView = [[CYPullRefreshSimpleTopView alloc] init];
__weak typeof(&*self) weakself = self;
UITableView *tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)];
tableView.backgroundView = nil;
tableView.delegate = self;
tableView.dataSource = self;
[tableView cy_addPullDownHanlder:^{
[weakself reloadData];
} topView:topView];
[tableView cy_addPullUpHandler:^{
[weakself loadMore];
} bottomView:bottomView];
[tableView cy_setPullUpEnable:NO];
[self.view addSubview:tableView];
_theTableView = tableView;
[_theTableView cy_triggerLoadWithState:CYLoadStatePullDown];
在加载数据完成后添加此功能
[_theTableView reloadData];
[_theTableView cy_stopLoad];
[_theTableView cy_setHasMoreData:_dataArray.count >= _limitNum ? YES : NO];
[_theTableView cy_setPullUpEnable:YES];
在加载数据完成后添加此功能
[_theTableView reloadData];
[_theTableView cy_stopLoad];
[_theTableView cy_setHasMoreData:dataArray.count >= _limitNum ? YES : NO];
你可以通过创建一个自定义视图来自定义安装CYPullRefreshViewProtocol。对于不同的状态,加载不同的UI。更多详细信息,请参阅CYPullRefreshSimpleTopView和CYPullRefreshSimpleBottomView。
这样,在不更改CYPullRefresh源代码的情况下,你可以进行高级定制。