- 一个实现了下拉刷新,上拉加载更多,上拉预加载功能的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压缩属性的表
本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们。
操作系统基础教程
戴维斯 / 第1版 (2006年7月1日) / 2006-7 / 34.0
这是一本关于操作系统基本原理的教科书,其最大特点就是从操作系统的分层概念出发,深入浅出地介绍了操作系统的基本概念和基本框架。本书可以作为高等院校非计算机专业相关课程的教材或参考书,也适合具有高中以上数学基础的计算机用户自学,还可以作为社会上计算机培训机构的教材。对所有想了解计算机操作系统,但又不需要或不打算深入学习其理论和实现细节的读者来说,本书是一本极具价值的入门指导书。一起来看看 《操作系统基础教程》 这本书的介绍吧!