一、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. .WrongArgumentException: Malformed database URL, failed to parse the connection string near ';characterEncoding=UTF-8&;serverTimezone=Asia/Shanghai'.)

    连接mysql库报的异常信息: org.springframework.transaction.CannotCreateTransactionException: Could not open JDB ...

  2. js相同的正则多次调用test()返回的值却不同

    项目中文件上传需要验证文件的格式,第一次正常,第二次就验证不通过了.在验证的地方console.log()两遍,发现结果不一样 !!! 正则和文件名都没变,但是两次的验证结果不同. this.reg ...

  3. 基于 Storyboard 多种方式的页面跳转、参数传递

    原文 通过按钮关联跳转 选中 Button ,然后点击 action 右边拖拽到 第二个页面 选择 "Show"即可完成跳转关联. 定义页面间 segue Id,通过代码触发跳转 ...

  4. R Data Frame

    https://www.datamentor.io/r-programming/data-frame/ Check if a variable is a data frame or not We ca ...

  5. django之查询操作及开启事务

    目录 聚合查询 aggregate 聚合函数 分组查询 annotate F与Q查询 F查询 Q查询 ORM操作事务 django中开启事务 聚合查询 aggregate 操作外键字段管理数据的时候, ...

  6. Linux—系统管理

    查看Linux系统版本                                                                    CentOS系统 # centos7查看命 ...

  7. (办公)访问其他系统接口httpClient,异步访问

    访问其他系统接口httpClient,但是都是同步的,同步意味当前线程是阻塞的,只有本次请求完成后才能进行下一次请求;异步意味着所有的请求可以同时塞入缓冲区,不阻塞当前的线程; httpClient请 ...

  8. Tornado(1)

    概述 Tornado 是 FriendFeed 使用的可扩展的非阻塞式 web 服务器及其相关工具的开源版本.这个 Web 框架看起来有些像web.py 或者 Google 的 webapp,不过为了 ...

  9. Day12- Python基础12 线程、GIL、Lock锁、RLock锁、Semaphore锁、同步条件event

    http://www.cnblogs.com/yuanchenqi/articles/6248025.html  博客地址 本节内容: 1:进程和线程的说明 2:线程的两种调用方式 3:threadi ...

  10. Re-stheasy

    https://dn.jarvisoj.com/challengefiles/ctf2.b93676be23733b2fcda3988c1133c1c1 用IDA-32bit 打开,找到main函数 ...