- 一个实现了下拉刷新,上拉加载更多,上拉预加载功能的tableViw
- 用的时候只要继承这个tableView即可实现上述功能,可以重写父类实现自定义样式。
效果
用法
- pod 'BSPreloadTableVew'
- 代码示例
- (void)viewDidLoad {
[super viewDidLoad];
self.pageSize = 20;
self.pageNum = 1;
[self setUpUI];
__weak typeof(self) weakeSelf = self;
[self.tableView setLoadNewData:^{
__strong typeof(weakeSelf) stongSelf = weakeSelf;
stongSelf.pageNum = 1;
[stongSelf fetchData];
}];
// [self.tableView setLoadMoreData:^{
// __strong typeof(weakeSelf) stongSelf = weakeSelf;
// [stongSelf fetchData];
// }];
[self.tableView preLoadDataThreshold4WithPageSize:self.pageSize initialPage:self.pageNum curPage:self.pageNum preLoadFetchBlk:^{
__strong typeof(weakeSelf) stongSelf = weakeSelf;
[stongSelf fetchData];
}];
[self showLoading];
[self fetchData];
}
- (void)fetchData{
NSDictionary *dict = @{
@"page":@(self.pageNum),
@"count":@(self.pageSize)
};
__weak typeof(self) weakeSelf = self;
[[BSRequestManager sharedInstance] postWithUrl:@"https://api.apiopen.top/getTangPoetry" args:dict finishBlk:^(NSDictionary * _Nonnull responseObject, NSError * _Nonnull error) {
__strong typeof(weakeSelf) stongSelf = weakeSelf;
[stongSelf.tableView endRefresh];
[stongSelf hideLoading];
if (error) {
[stongSelf.view makeToast:error.localizedDescription];
stongSelf.tableView.isPreLoadRefreshing = NO;
return ;
}
//请求成功
if (stongSelf.pageNum == 1){
NSArray *arrTemp = responseObject[@"result"];
stongSelf.arrMList = [NSMutableArray arrayWithArray:arrTemp];
if (stongSelf.arrMList.count == 0) {
//无数据缺省页
return ;
} else if (stongSelf.arrMList.count < stongSelf.pageSize) {
[stongSelf.tableView hideFooter];
stongSelf.tableView.isPreLoadLastPage = YES;
} else {
[stongSelf.tableView showFooter];
}
[stongSelf.tableView reloadData];
} else {
NSArray *arrTemp = responseObject[@"result"];
[stongSelf.arrMList addObjectsFromArray:arrTemp];
[stongSelf.tableView reloadData];
if (arrTemp.count < stongSelf.pageSize) {
stongSelf.tableView.isPreLoadLastPage = YES;
[stongSelf.tableView hideFooter];
} else {
[stongSelf.tableView showFooter];
}
}
stongSelf.pageNum ++;
stongSelf.tableView.isPreLoadRefreshing = NO;
}];
}
#pragma mark - UITableViewDelegate
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
return self.arrMList.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
UITableViewCell *cell = nil;
TableViewCellTest *cellTest = [self.tableView dequeueReusableCellWithIdentifier:@"TableViewCellTest"];
cellTest.data = self.arrMList[indexPath.row];
cell = cellTest;
return cell;
}
- (void)showLoading{
[MBProgressHUD showHUDAddedTo:self.view animated:YES];
}
- (void)hideLoading{
[MBProgressHUD hideHUDForView:self.view animated:YES];
}
复制代码
以上就是本文的全部内容,希望本文的内容对大家的学习或者工作能带来一定的帮助,也希望大家多多支持 码农网
猜你喜欢:- 带有列表的Spring @Cacheable方法
- python – 带有分档范围的熊猫条形图
- 是否可以从管道上传带有cURL的文件?
- KDevelop 5.4 正式发布,带有 Meson 支持
- Vulkan 1.1.128 发布,带有性能查询扩展
- HBase无法创建带有snappy压缩属性的表
本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们。
SEM修炼手册:百度竞价、信息流广告、数据分析与专题页策划实战详解
陈丰洲 / 电子工业出版社 / 2018-10 / 59.80元
SEM人员在职场打拼的过程中,会遇到一个又一个坑,《SEM修炼手册:百度竞价、信息流广告、数据分析与专题页策划实战详解》尝试站在一定的高度,将从业者从专员走向管理岗位过程中可能碰到的问题进行整理,不仅谈竞价推广,也谈基于SEM的营销体系。 《SEM修炼手册:百度竞价、信息流广告、数据分析与专题页策划实战详解》包括11章内容,由浅入深地分享SEM的进阶过程。第1章是SEM概述,让读者对SEM有......一起来看看 《SEM修炼手册:百度竞价、信息流广告、数据分析与专题页策划实战详解》 这本书的介绍吧!