UITableView出现卡顿如何处理
tableView的beginUpdate和endUpdate要比reloadData和reloadRowsAtIndexPaths好,因为beginUpdate和endUpdate会执行一个动画block,图片加载的时候显的很平滑。你自己试一下就知道了。
加载图片的时候要用多线程,要用缓存,也就是需要异步加载
计算cell的高度的时候要尽量的简单,因为tableVIew中cell的高度是一次性加载完的
要用重用机制,一定要用,不然会卡的
用户习惯性快速的滚动,视图和数据内容都会快速的变化,如果效率问题处理不好,很容易有卡顿的现象。造成用户体验的降低。
数据刷新
如果我们的modle更新了。相应的要体现到UITableView上面。简单的我们可以reload整个TableView。这样做很方便,而且数据上没有问题。唯一的问题就是,reload整个TableView的效率太低了。而且,往往我们只是少数的Cell内容变化。所以没有必要去reload整个TableView。而是那条数据变化去刷新对应的Cell就好了。这样做效率提高很多。
具体涉及到的几个函数
- (void)beginUpdates;
- (void)endUpdates; - (void)insertSections:(NSIndexSet *)sections withRowAnimation:(UITableViewRowAnimation)animation;
- (void)deleteSections:(NSIndexSet *)sections withRowAnimation:(UITableViewRowAnimation)animation;
- (void)reloadSections:(NSIndexSet *)sections withRowAnimation:(UITableViewRowAnimation)animation; - (void)insertRowsAtIndexPaths:(NSArray *)indexPaths withRowAnimation: (UITableViewRowAnimation)animation;
- (void)deleteRowsAtIndexPaths:(NSArray *)indexPaths withRowAnimation: (UITableViewRowAnimation)animation;
- (void)reloadRowsAtIndexPaths:(NSArray *)indexPaths withRowAnimation:(UITableViewRowAnimation)animation;
我自己遇到的情况:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell; switch (indexPath.row) {
case :
// 初始化抢红包Cell
cell = [tableView dequeueReusableCellWithIdentifier:reuseIdentifier_rob forIndexPath:indexPath];
[self setupRobRedPackageCell:cell];
break;
case :
// 初始化轮播Cell
cell = [tableView dequeueReusableCellWithIdentifier:reuseIdentifier_ad forIndexPath:indexPath];
[self setupAdCarouseCell:cell];
break;
case :
// 初始化趣味答题Cell
cell = [tableView dequeueReusableCellWithIdentifier:reuseIdentifier_answer forIndexPath:indexPath];
[self setupInterestingAnswerCell:cell];
break;
case :
// 初始化排行榜Cell
cell = [tableView dequeueReusableCellWithIdentifier:reuseIdentifier_charts forIndexPath:indexPath];
[self setupChartsCell:cell];
break;
case :
// 初始化折扣优惠区Cell
cell = [tableView dequeueReusableCellWithIdentifier:reuseIdentifier_discount forIndexPath:indexPath];
[self setupDiscountCell:cell];
break;
}
cell.selectionStyle = UITableViewCellSelectionStyleNone;
return cell;
}
其中的[self setupxxxx]用来创建和添加各种视图到Cell的contentView中, 由于没有判断仔细, 导致每次重用cell的时候都会调用到, 所以照成了卡顿, 以下是修改后的代码:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell; switch (indexPath.row) {
case :
// 初始化抢红包Cell
cell = [tableView dequeueReusableCellWithIdentifier:reuseIdentifier_rob forIndexPath:indexPath];
if (self.cellReuseTag >= ) break;
[self setupRobRedPackageCell:cell];
self.cellReuseTag = ;
break;
case :
// 初始化轮播Cell
cell = [tableView dequeueReusableCellWithIdentifier:reuseIdentifier_ad forIndexPath:indexPath];
if (self.cellReuseTag >= ) break;
[self setupAdCarouseCell:cell];
self.cellReuseTag = ;
break;
case :
// 初始化趣味答题Cell
cell = [tableView dequeueReusableCellWithIdentifier:reuseIdentifier_answer forIndexPath:indexPath];
if (self.cellReuseTag >= ) break;
[self setupInterestingAnswerCell:cell];
self.cellReuseTag = ;
break;
case :
// 初始化排行榜Cell
cell = [tableView dequeueReusableCellWithIdentifier:reuseIdentifier_charts forIndexPath:indexPath];
if (self.cellReuseTag >= ) break;
[self setupChartsCell:cell];
self.cellReuseTag = ;
break;
case :
// 初始化折扣优惠区Cell
cell = [tableView dequeueReusableCellWithIdentifier:reuseIdentifier_discount forIndexPath:indexPath];
if (self.cellReuseTag >= ) break;
[self setupDiscountCell:cell];
self.cellReuseTag = ;
break;
}
cell.selectionStyle = UITableViewCellSelectionStyleNone;
return cell;
}
简单的, 也就是搞多一个标记来记录cell已经初始化过, 跳过初始化的步骤
UITableView出现卡顿如何处理的更多相关文章
- UITableView cell复用出错问题 页面滑动卡顿问题 & 各杂七杂八问题
UITableView 的cell 复用机制节省了内存,但是有时对于多变的自定义cell,重用时会出现界面出错(例如复用出错,出现cell混乱重影).滑动卡顿等问题,这里只简单敲下几点复用出错时的解决 ...
- 记一次简单的UITableView卡顿优化
先说需求,要做一个类似这种的列表 标签控件直接用的第三方 YZTagList 不知道的可以去搜一下,当这不重要. 重要的是这个控件加载数据的时候非常影响列表滑动效果,造成卡顿,尤其是列表行数如果更多的 ...
- Vegas常见问题解答,如何处理预览卡顿
制作视频并不是简单的拼拼凑凑,很多时候我们都需要给视频加上一些视频特效或转场等效果,如果只是图片素材的话,还不会出现卡顿的现象,但是当你给视频添加了效果后,在预览窗口看到的就是非常卡顿了.除了本身计算 ...
- 第3月30天 UIImage imageWithContentsOfFile卡顿 Can't add self as subview MPMoviePlayerControlle rcrash
1. UIImage imageWithContentsOfFile卡顿 [[UIImage alloc] initWithContentsOfFile 卡顿 2.uitableview scroll ...
- 想让安卓app不再卡顿?看这篇文章就够了
欢迎大家前往腾讯云+社区,获取更多腾讯海量技术实践干货哦~ 本文由likunhuang发表于云+社区专栏 实现背景 应用的使用流畅度,是衡量用户体验的重要标准之一.Android 由于机型配置和系统的 ...
- iOS之tableView性能优化/tableView滑动卡顿?
本文围绕以下几点展开tableView性能优化的论述? 1.UITableViewCell重用机制? 2.tableView滑动为什么会卡顿? 3.优化方法? 4.总结 1.UITableViewCe ...
- xamarin MasterDetailPage点击Master时卡顿现象
在很多项目中经常会使用到MasterDetailPage的布局方式,而且一般做为主页面来开发,在开发中,发现一个并不算Bug的问题,但是却发生了,以此记录下来,方便大家探讨. 现象是这样的,我开发了一 ...
- 解决UINavigationController在pushViewController时出现的"卡顿"问题
进行开发中,遇到了个小问题: 在使用UINavigationController的-pushViewController:animated:执行入栈一个子控制器操作时(即最新栈顶子控制器),会出现推出 ...
- webstorm卡顿问题
近期随着项目开展,文件逐渐增大,webstrom频繁出现卡顿,而且时有崩溃现象,提示没有足够的内存来执行请求的操作,需要增加Xms设置. 解决办法: 1.找到WebStorm.exe.vmoption ...
随机推荐
- ASP.NET MVC的Action Filter
一年前写了一篇短文ASP.NET MVC Action Filters,整理了Action Filter方面的资源,本篇文章详细的描述Action Filter.Action Filter作为一个可以 ...
- python的sorted相关
Python 字典排序 在python里,字典是内置的数据类型,是个无序的存储结构,每一个元素是key-value对: 有关key的解释: sorted(L,key=by_name)中的key即by_ ...
- HTML5 Web socket和socket.io
what is websockets Two-way communication over ont TCP socket, a type of PUSH technology HTML5的新特性,用于 ...
- Visual Studio创建跨平台移动应用_03.AppBuilder Extension
1 背景 本章节是关于Telerik AppBuilder for Visual Studio的. 目前(2014.12)为Telerik公司Telerik Platform的一部分,Telerik ...
- Intel 英特尔
英特尔 英特尔 基本资料 公司名称:英特尔(集成电路公司) 外文名称:Intel Corporation(Integrated Electronics Corporation) 总部地 ...
- Hive学习笔记【转载】
本文转载自:http://blog.csdn.net/haojun186/article/details/7977565 1. HIVE结构 Hive 是建立在 Hadoop 上的数据仓库基础构架. ...
- Exception starting filter struts2 java.lang.NoClassDefFoundError: org/objectweb/asm/ClassVisitor
按教程,使用Convention插件进行配置 教程中说只要加入struts2-convention-plugin-2.3.4.1.jar这个jar包就可以使用. 按照这种方法部署后,启动tomcat报 ...
- UVA127- "Accordian" Patience(模拟链表)
"Accordian" Patience You are to simulate the playing of games of ``Accordian'' patience, t ...
- AFNetworking (3.1.0) 源码解析 <三>
今天要介绍的是Reachability文件夹下的AFNetworkReachabilityManager类.通过字面意思我们就可以知道AFNetworkReachabilityManager是用来监测 ...
- Java 编程的动态性,第3部分: 应用反射--转载
在 上个月的文章中,我介绍了Java Reflection API,并简要地讲述了它的一些基本功能.我还仔细研究了反射的性能,并且在文章的最后给出了一些指导方针,告诉读者在一个应用程序中何时应该使用反 ...