一、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. GO-&获取地址与*解引用

    &变量 获取变量在内存空间的地址 *变量地址 获取变量的值 一.普通数据 package main import "fmt" func main(){ b :=1111 c ...

  2. Docker 镜像与容器

    镜像和容器的关系   容器提交    commint 作用:       根据容器生成一个新的镜像        命令格式:       docker commit [OPTIONS] CONTAIN ...

  3. Java生鲜电商平台-订单模块状态机架构设计

    Java生鲜电商平台-订单模块状态机架构设计 说明:在Java生鲜电商平台中订单的状态流转业务        我们知道 一个订单会有很多种状态:临时单.已下单.待支付.待收货.待评价.已完成,退货中等 ...

  4. 操作系统篇之Linux命令操作和redis安装以及基本使用

    电脑操作系统 : windows7,8,10,xp,win98 操作系统 : linux ax unix 以后开发项目是部署在服务器上,服务器一般采用linux. linux的优点:系统稳定,操作速度 ...

  5. IT 常用的网址

    IT 常用的网址 将图片转换成网络图片的网址:https://sm.ms/ 生成 ico 图标: http://www.bitbug.net/ 动画特效: https://daneden.github ...

  6. jQuery从零开始(二)

    1.css类的操作 -----addClass() 向被选元素添加一个或者多个类 -----removeClass() 删除被选元素的类 -----toggleClass() 取反 -----css( ...

  7. 【React Native】在原生和React Native间通信(RN调用原生)

    一.从React Native中调用原生方法(原生模块) 原生模块是JS中也可以使用的Objective-C类.一般来说这样的每一个模块的实例都是在每一次通过JS bridge通信时创建的.他们可以导 ...

  8. redis windows版安装

    首先到 https://github.com/ServiceStack/redis-windows 下载redis 然后将下载的文件解压 然后获取里面的这个压缩包并且解压 这是2.8.2101版本的, ...

  9. LeetCode刷题191119

    博主渣渣一枚,刷刷leetcode给自己瞅瞅,大神们由更好方法还望不吝赐教.题目及解法来自于力扣(LeetCode),传送门. 算法: 给定一个非负整数数组,你最初位于数组的第一个位置. 数组中的每个 ...

  10. Word List 1

    前言 图片均来源网络 文章目录 前言 1.1 Super computer 1.2 Mainframe 1.3 Server 1.4 Desktop PC 1.5 Notebook or Laptop ...