BSPreloadTableVew带有预加载功能的tableView

栏目: IOS · 发布时间: 4年前

  1. 一个实现了下拉刷新,上拉加载更多,上拉预加载功能的tableViw
  2. 用的时候只要继承这个tableView即可实现上述功能,可以重写父类实现自定义样式。

效果

BSPreloadTableVew带有预加载功能的tableView

用法

  1. pod 'BSPreloadTableVew'
  2. 代码示例
- (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];
}
复制代码

以上就是本文的全部内容,希望本文的内容对大家的学习或者工作能带来一定的帮助,也希望大家多多支持 码农网

查看所有标签

猜你喜欢:

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

爆品方法论

爆品方法论

陈轩 / 2019-1-6 / 49

作者利用自己在品牌定位和爆品营销领域十三年的实践历练,结合移动社交媒体、爆品营销策略和社会心理学,精心筛选出上百个经典的营销案例,既分享了爆品内容的炮制方法和营销原理,也分享了爆品内容的推广技巧,告诉读者如何用移动社交媒体来颠覆传统营销模式,如何用互联网思维来玩转营销,实现低成本、高销量、大传播,成功打造市场爆品。一起来看看 《爆品方法论》 这本书的介绍吧!

RGB转16进制工具
RGB转16进制工具

RGB HEX 互转工具

SHA 加密
SHA 加密

SHA 加密工具

XML、JSON 在线转换
XML、JSON 在线转换

在线XML、JSON转换工具