前言
UITableView是iOS开发中常见的控件,其加载多条完数据一般用到分页,上拉加载更多数据时预加载可以增加用户体验感
提示:以下是本篇文章正文内容,下面案例可供参考
一、预加载是什么?
示例:就是表格分页滑动的时候没有断断续续的视觉,给用户滑动流畅的体验感。
二、使用步骤
1.引入库
代码如下(示例):
target ‘****’ do
platform :ios, ‘9.0’
#define 常用
pod ‘AFNetworking’, ‘~> 3.2.1’
pod ‘MJRefresh’, ‘~> 3.2.0’
#忽略版本警告
inhibit_all_warnings!
## 2.读入数据
<font color=#999AAA >代码如下(示例)
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return _listArrary.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:@"Cell" forIndexPath:indexPath];
cell.model=model;
return cell;
}
- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
{
NSInteger row = [indexPath row];
if (row == self.listArrary.count -3)
{
self.page++;//第几页
[self askList];
}
}
page就是分页码,askList就是数据请求方法
# 总结
<font color=#999AAA >提示:方法很简单,效果很明显,小编菜鸟开发,期待同行共勉