iOS 高效的分页加载(TableView、CollectionView)
一、tableview的分页加载的代码对比
没有优化之前的代码如下
[strongSelf.tableView.mj_footer endRefreshing];
[strongSelf.articleArr addObjectsFromArray:feedList];
[strongSelf.tableView reloadData];
优化之后的代码
NSMutableArray *indexPaths = [NSMutableArray array];
[feedList enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) { NSIndexPath *indexPath = [NSIndexPath indexPathForRow:(strongSelf.articleArr.count + idx) inSection:];
[indexPaths addObject:indexPath];
}]; [strongSelf.tableView.mj_footer endRefreshing]; [strongSelf.articleArr addObjectsFromArray:feedList]; [strongSelf.tableView beginUpdates];
[strongSelf.tableView insertRowsAtIndexPaths:indexPaths withRowAnimation:UITableViewRowAnimationNone];
[strongSelf.tableView endUpdates];
二、collectonview的分页加载的代码对比
没有优化之前的代码如下:
[strongSelf.feedList addObjectsFromArray:feedList];
if (feedList.count < kPageSize) { [strongSelf.collectionView.mj_footer endRefreshingWithNoMoreData];
}else{ [strongSelf.collectionView.mj_footer resetNoMoreData];
}
[strongSelf.collectionView reloadData];
优化之后的代码
NSMutableArray *indexPaths = [NSMutableArray array];
[feedList enumerateObjectsUsingBlock:^(id _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) { [indexPaths addObject:[NSIndexPath indexPathForItem:(strongSelf.feedList.count + idx) inSection:]];
}]; [strongSelf.feedList addObjectsFromArray:feedList];
if (feedList.count < kPageSize) { [strongSelf.collectionView.mj_footer endRefreshingWithNoMoreData];
}else{ [strongSelf.collectionView.mj_footer resetNoMoreData];
}
[strongSelf.collectionView insertItemsAtIndexPaths:indexPaths];
总结:相比较之下,优化之后看似代码量增加了少许,但是从理论上分页加载的性能更好了。之前分页加载使用的全局刷新,优化之后改用了局部刷新。从而性能得到提升。
iOS 高效的分页加载(TableView、CollectionView)的更多相关文章
- java攻城狮之路(Android篇)--widget_webview_metadata_popupwindow_tabhost_分页加载数据_菜单
一.widget:桌面小控件1 写一个类extends AppWidgetProvider 2 在清单文件件中注册: <receiver android:name=".ExampleA ...
- Android基本控件之listView(三)<用ListView实现分页加载>
我们之前讨论了ListView的基本使用方法和ListView的优化 今天我们再来讨论一个关于ListView的一个新的东西~就是分页加载.那么什么是分页加载呢?简单点说,就是"下拉刷新&q ...
- Android ListView分页加载时图片显示问题
场景:Android ListView需要分页加载,每个item中会有图片,图片又是从网络下载的. 问题:在滑动加载下一页时,上一页的图片明明已经下载完成了,但是无法显示出来. Bug重现: 1,加载 ...
- Android中ListView分页加载数据
public class MainActivity extends Activity { private ListView listView=null; //listview的数据填充器 privat ...
- IOS 多个UIImageView 加载高清大图时内存管理
IOS 多个UIImageView 加载高清大图时内存管理 时间:2014-08-27 10:47 浏览:59人 当我们在某一个View多个UIImageView,且UIImageView都显示的是 ...
- ListView上拉刷新和分页加载完整的Dome
很多人工作的过程中都会碰到ListView下拉刷新和分页加载,然后大多数公司都已经把框架写好了,大家直接用就可以了,有些人一直对这个事情处于迷茫状态,为了让大家对上拉刷新和分页加载有一个比较全面的认识 ...
- 【Android进阶】Listview分页加载数据的实现
Listview分页加载数据的实现 public class MainActivity extends Activity { protected static final int SUCCESS_GE ...
- Jetpack 架构组件 Paging 分页加载 MD
Markdown版本笔记 我的GitHub首页 我的博客 我的微信 我的邮箱 MyAndroidBlogs baiqiantao baiqiantao bqt20094 baiqiantao@sina ...
- [转]微信小程序之加载更多(分页加载)实例 —— 微信小程序实战系列(2)
本文转自;http://blog.csdn.net/michael_ouyang/article/details/56846185 loadmore 加载更多(分页加载) 当用户打开一个页面时,假设后 ...
随机推荐
- Wpf Dispatcher.BeginInvoke((Action)delegate{}));
<Window x:Class="WpfApplication1.MainWindow" xmlns="http://schemas.microsoft.com/w ...
- RandomAccessFile()实现用户注册功能, 新增,查询,更新
package seday03.raf;import java.io.IOException;import java.io.RandomAccessFile;import java.util.Arra ...
- [转]VBA Check if an outlook folder exists; if not create it
本文转自:http://www.outlookcode.com/d/code/quarexe.htm To quarantine application file attachments This O ...
- iOS 为何使用runtime方法交换多次后却能按照交换顺序依次执行代码逻辑?
题目: 假设我们有一个ViewController, Category A(ViewController), Category B(ViewController), Category C(ViewCo ...
- flvjs的unload(),detachMediaElement(),destroy()报错,undefined,not a function解决方案
首先,真的被网上一堆各种转载复制粘贴坑了不少,最后直接到GitHub上flvjs的看作者的demo和docs才解决,具体如下. 1.引入flvjs文件,新建实例 var flvUrl = '直播流地址 ...
- centos7.6使用openssl生成CA签署的证书个人实验笔记
准备:客户端centos6.10 服务端Centos7.6 实验:客户端生成证书请求,服务端颁发证书,最后吊销其中一个证书 1.先在服务端上的/etc/pki/CA/目录生成rsa的私钥: 2.在服 ...
- 移动网络游戏实现流程——并借此阐明pomelo在GitHub上各个项目间的关系
<!DOCTYPE html> 摘要:本文通过一个简易流程图介绍如何基于Cocos2d-x引擎和pomelo服务器框架开发一个移动网络游戏.并借此阐明pomelo提供的各个项目间的关系. ...
- 自己收集的好玩的JS特效(持续更新)
放到我自己的服务器上了. 网 scale.html 樱花 sakura.html
- Codeforces Round #597 (Div. 2) E. Hyakugoku and Ladders 概率dp
E. Hyakugoku and Ladders Hyakugoku has just retired from being the resident deity of the South Black ...
- centos安装nodejs并配置生产环境,基于pm2
安装nodejs和yarn的命令: curl --silent --location https://dl.yarnpkg.com/rpm/yarn.repo | sudo tee /etc/yum. ...