Home  >  Q&A  >  body text

ios - UITableView卡顿,app退出到后台再打开,就流畅了?

我的app有两个主要的tableView,用来展示大量图片:

一个从本地数据库加载数据、显示本地图片,一个从网络加载数据和图片。

本地的采用普通tableView,联网的采用瀑布流(PSCollectionView)来实现,后者是基于tableView的开源类库。

二者的层级结构差不多,都做了同样的优化:复用(UI和数据分离)、提前计算好数据滑动时只获取数值、图片都用SDWebImage异步加载。

本地的rowHeight一致,无需计算;联网的由于是瀑布流,所有cell宽度一致,高度随图片变化,提前从服务器数据表获取所有的图片的长宽比,根据本地要显示的宽度,乘以比例得出高度,算好每个cell的高度,存为数组,滑动时从数组直接获取当前cell的高度。

现在的情况是这样的:

真机调试,iOS9.2,iPhone6s。我启动app,进入本地tableView页面,滑动很流畅。然后我进入联网的页面,滑动时候明显有卡顿。这时我切换到本地的页面,发现本地页面变的和联网页面一样卡顿。

并且... 只要按home键退出到后台,再马上打开,这时候居然两个tableView都非常流畅,一点都不卡,瀑布流怎么上拉加载新的数据都不会卡。而且有个小细节就是从后台回到前台的一瞬间,tableView很轻微的闪了一下,有时候还带点位移。我估计这点很关键。这一瞬间,系统到底做了什么操作呢?

我的个人测试和分析:

我去掉图片加载,发现情况差不多,证明与图片关系不大。关键点在于为什么两个tableView滑动流畅性被绑定了???退出到后台的瞬间,系统做了什么动作导致了tableView变流畅,我想这个应该就是我的app联网页面tableView卡顿的解决办法吧。

有没有人遇到过类似的问题,或者能看出问题所在,感谢指点!

怪我咯怪我咯2716 days ago222

reply all(2)I'll reply

  • 高洛峰

    高洛峰2017-04-17 17:23:23

    Place download tasks in other threads and do not block the main thread. In addition, if there are a large number of pictures, you can consider using a custom View to replace the original imageView of UITableViewCell. Also don’t set a transparent View

    reply
    0
  • 高洛峰

    高洛峰2017-04-17 17:23:23

    It is estimated that there is a memory leak. We still need to look for this in detail, and all views should not be transparent. Because the slide will freeze after a while, it is obvious that there is some strong reference that caused the memory leak. It should be good to control the number of pictures downloaded at the same time. If you find the reason, please let me know.

    reply
    0
  • Cancelreply