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出现卡顿如何处理的更多相关文章

  1. UITableView cell复用出错问题 页面滑动卡顿问题 & 各杂七杂八问题

    UITableView 的cell 复用机制节省了内存,但是有时对于多变的自定义cell,重用时会出现界面出错(例如复用出错,出现cell混乱重影).滑动卡顿等问题,这里只简单敲下几点复用出错时的解决 ...

  2. 记一次简单的UITableView卡顿优化

    先说需求,要做一个类似这种的列表 标签控件直接用的第三方 YZTagList 不知道的可以去搜一下,当这不重要. 重要的是这个控件加载数据的时候非常影响列表滑动效果,造成卡顿,尤其是列表行数如果更多的 ...

  3. Vegas常见问题解答,如何处理预览卡顿

    制作视频并不是简单的拼拼凑凑,很多时候我们都需要给视频加上一些视频特效或转场等效果,如果只是图片素材的话,还不会出现卡顿的现象,但是当你给视频添加了效果后,在预览窗口看到的就是非常卡顿了.除了本身计算 ...

  4. 第3月30天 UIImage imageWithContentsOfFile卡顿 Can't add self as subview MPMoviePlayerControlle rcrash

    1. UIImage imageWithContentsOfFile卡顿 [[UIImage alloc] initWithContentsOfFile 卡顿 2.uitableview scroll ...

  5. 想让安卓app不再卡顿?看这篇文章就够了

    欢迎大家前往腾讯云+社区,获取更多腾讯海量技术实践干货哦~ 本文由likunhuang发表于云+社区专栏 实现背景 应用的使用流畅度,是衡量用户体验的重要标准之一.Android 由于机型配置和系统的 ...

  6. iOS之tableView性能优化/tableView滑动卡顿?

    本文围绕以下几点展开tableView性能优化的论述? 1.UITableViewCell重用机制? 2.tableView滑动为什么会卡顿? 3.优化方法? 4.总结 1.UITableViewCe ...

  7. xamarin MasterDetailPage点击Master时卡顿现象

    在很多项目中经常会使用到MasterDetailPage的布局方式,而且一般做为主页面来开发,在开发中,发现一个并不算Bug的问题,但是却发生了,以此记录下来,方便大家探讨. 现象是这样的,我开发了一 ...

  8. 解决UINavigationController在pushViewController时出现的"卡顿"问题

    进行开发中,遇到了个小问题: 在使用UINavigationController的-pushViewController:animated:执行入栈一个子控制器操作时(即最新栈顶子控制器),会出现推出 ...

  9. webstorm卡顿问题

    近期随着项目开展,文件逐渐增大,webstrom频繁出现卡顿,而且时有崩溃现象,提示没有足够的内存来执行请求的操作,需要增加Xms设置. 解决办法: 1.找到WebStorm.exe.vmoption ...

随机推荐

  1. javaWeb遍历获取session中的值

    //方法一:通过遍历的方法进行遍历 String FileName=""; HttpSession session=request.getSession();//获取session ...

  2. JS简易时钟

    HTML <div id="clock"> <span></span>:<span></span>:<span&g ...

  3. 如何改变dreamweaver的编码方式

  4. Ant快速入门(三)-----定义生成文件

    适应Ant的关键就是编写生成文件,生成文件定义了该项目的各个生成任务(以target来表示,每个target表示一个生成任务),并定义生成任务之间的依赖关系. Ant生成文件的默认名为build.xm ...

  5. Oulipo

    poj3461:http://poj.org/problem?id=3461 题意:求一个串在另一个串中出现的次数. 题解:直接套用KMP即可,在统计的时候做一下修改.找到之后不是直接返回,而是移动i ...

  6. j2ee爬坑行之二 servlet

    servlet生命周期 web容器加载servlet 类 web容器调用servlet的构造函数,初始化servlet. web容器调用servlet的init()方法.注意该方法在servlet的一 ...

  7. Go语言开发环境安装

    Go是Google开发的一种编译型,並發型,并具有垃圾回收功能的编程语言. 去http://golang.org/doc/install#download 下载相应的版本. 1.安装go语言:2.将g ...

  8. 【HDOJ】5154 Harry and Magical Computer

    拓扑排序. /* 5154 */ #include <iostream> #include <cstdio> #include <cstring> #include ...

  9. Wi-Fi定位,AP定位

    Wi-Fi实时定位系统 基于Wi-Fi的无线局域网实时定位系统(Wi-Fi RTLS)结合无线局域网络(WLAN).射频识别(RFID)和实时定位等多种技术,广泛地应用在有无线局域网覆盖的区域,实现复 ...

  10. 【转】vim 修改tab为四个空格

    原文网址:http://blog.sina.com.cn/s/blog_620ccfbf01010erz.html 为了vim更好的支持python写代码,修改tab默认4个空格有两种设置方法: 1. ...