一、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)的更多相关文章

  1. java攻城狮之路(Android篇)--widget_webview_metadata_popupwindow_tabhost_分页加载数据_菜单

    一.widget:桌面小控件1 写一个类extends AppWidgetProvider 2 在清单文件件中注册: <receiver android:name=".ExampleA ...

  2. Android基本控件之listView(三)<用ListView实现分页加载>

    我们之前讨论了ListView的基本使用方法和ListView的优化 今天我们再来讨论一个关于ListView的一个新的东西~就是分页加载.那么什么是分页加载呢?简单点说,就是"下拉刷新&q ...

  3. Android ListView分页加载时图片显示问题

    场景:Android ListView需要分页加载,每个item中会有图片,图片又是从网络下载的. 问题:在滑动加载下一页时,上一页的图片明明已经下载完成了,但是无法显示出来. Bug重现: 1,加载 ...

  4. Android中ListView分页加载数据

    public class MainActivity extends Activity { private ListView listView=null; //listview的数据填充器 privat ...

  5. IOS 多个UIImageView 加载高清大图时内存管理

    IOS 多个UIImageView 加载高清大图时内存管理 时间:2014-08-27 10:47  浏览:59人 当我们在某一个View多个UIImageView,且UIImageView都显示的是 ...

  6. ListView上拉刷新和分页加载完整的Dome

    很多人工作的过程中都会碰到ListView下拉刷新和分页加载,然后大多数公司都已经把框架写好了,大家直接用就可以了,有些人一直对这个事情处于迷茫状态,为了让大家对上拉刷新和分页加载有一个比较全面的认识 ...

  7. 【Android进阶】Listview分页加载数据的实现

    Listview分页加载数据的实现 public class MainActivity extends Activity { protected static final int SUCCESS_GE ...

  8. Jetpack 架构组件 Paging 分页加载 MD

    Markdown版本笔记 我的GitHub首页 我的博客 我的微信 我的邮箱 MyAndroidBlogs baiqiantao baiqiantao bqt20094 baiqiantao@sina ...

  9. [转]微信小程序之加载更多(分页加载)实例 —— 微信小程序实战系列(2)

    本文转自;http://blog.csdn.net/michael_ouyang/article/details/56846185 loadmore 加载更多(分页加载) 当用户打开一个页面时,假设后 ...

随机推荐

  1. css 揭秘-读书笔记

    css 揭秘 [希]Lea verou 著 css 魔法 译 该书涵盖7大主题,47个css技巧,是css进阶必备书籍,开阔思路,探寻更优雅的解决方案.这本书完全用css渲染出的html写成的(布局. ...

  2. [Spring cloud 一步步实现广告系统] 13. 索引服务编码实现

    上一节我们分析了广告索引的维护有2种,全量索引加载和增量索引维护.因为广告检索是广告系统中最为重要的环节,大家一定要认真理解我们索引设计的思路,接下来我们来编码实现索引维护功能. 我们来定义一个接口, ...

  3. Linux gzip: stdin: not in gzip format

    在解压tar.gz文件的时候报错 tar -zxvf otp_src_18.3.tar.gz gzip: stdin: not in gzip format tar: Child returned s ...

  4. CentOS 7.x 安装 ZSH 终端

    一.安装基本组件 首先执行 yum 命令来安装需要的 zsh 原始程序与 git 程序来 pull 代码. yum install -y zsh git 安装 oh my zsh 脚本 (这一步需要安 ...

  5. jquery实现get的异步请求

    <%@ page contentType="text/html;charset=UTF-8" language="java" %><html& ...

  6. 简单sql注入学到的延时盲注新式攻击

    0x01 知识点 mysql_pconnect(server,user,pwd,clientflag) mysql_pconnect() 函数打开一个到 MySQL 服务器的持久连接. mysql_p ...

  7. angularjs路由传值$routeParams

    AngularJS利用路由传值, 1.导包 <script src="angular.min.js"></script> <script src=&q ...

  8. Linux—磁盘管理

    https://www.cnblogs.com/new-journey/p/10076387.html https://www.cnblogs.com/jiangxiaoxian/p/9610903. ...

  9. vue模板语法上

    vue的插值案例 <!DOCTYPE html> <html> <head> <meta charset="utf-8"> < ...

  10. HashMap默认加载因子为什么选择0.75?(阿里)

    Hashtable 初始容量是11 ,扩容 方式为2N+1; HashMap 初始容量是16,扩容方式为2N; 阿里的人突然问我为啥扩容因子是0.75,回来总结了一下: 提高空间利用率和 减少查询成本 ...