UITableView的加载缓慢.怎么知道为什么? [英] Slow loading of UITableView. How know why?

查看:47
本文介绍了UITableView的加载缓慢.怎么知道为什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个UITableView,它显示一长串数据.使用部分并遵循如何解决UITableView中的缓慢滚动的建议. /p>

流程是加载主UITableView&一秒钟从那里选择一行.

但是,要显示3000项内容,需要11秒钟才能显示.我从sqlite的记录加载中首先怀疑(我预加载了前200个).所以我只削减了50.

但是,无论我预加载1还是500,时间都是一样的.

该视图是由IB创建的,并且都是不透明的.

关于如何发现问题,我没有足够的想法.我运行仪器工具,但不知道要看什么.

此外,当用户从以前的UITable中选择一个单元格时,一段时间内都不会显示任何视觉反馈(即,该单元格未被选中),因此他认为自己没有选择它并尝试了几次.与这个问题有关.

该怎么办?

注意:问题仅在实际设备上出现:

  • 第二代iPod Touch
  • 使用fmdb作为sqlite api
  • 在viewDidLoad中进行缓存
  • 使用NSDictionary进行缓存
  • 为缓存部分使用NSAutoreleasePool.
  • 仅缓存行ID&显示单元格数据所需的mac 4字段
  • 使用界面生成器SDK 2.2.1制作的UIView
  • 仪器说我在设备上使用了2.5 MB

解决方案

-[FMResultSet next]调用可能是非常昂贵的调用,具体取决于要加载的数据.在此调用过程中,sqlite实际上将进入数据库,找到要返回的下一行,并为您提供适当的字段.它不仅仅是一个枚举器.

您可能要考虑在实际显示表格之前预先缓存所有数据.这意味着您将在表显示在屏幕上之前完成所有FMDB调用.

如果花费的时间太长,则可能要显示带有初始行的表格视图,然后使用NSOperations或仅使用第二个线程在后台加载数据并以这种方式对其进行缓存.

I have a UITableView that show a long list of data. Use sections and follow the sugestion of How to solve slow scrolling in UITableView .

The flow is load a main UITableView & push a second selecting a row from there.

However, with 3000 items take 11 seconds to show. I suspect first from the load of the records from sqlite (I preload the first 200). So I cut it to only 50.

However, no matter if I preload only 1 or 500, the time is the same.

The view is made from IB and all is opaque.

I run out of ideas in how detect the problem. I run the Instruments tool but not know what to look.

Also, when the user select a cell from the previous UITable, no visual feedback is show (ie: the cell not turn selected) for a while so he thinks he not select it and try several times. Is related to this problem.

What to do?

NOTE: The problem is only in the actual device:

  • iPod Touch 2d generation
  • Using fmdb as sqlite api
  • Doing the caching in viewDidLoad
  • Using NSDictionary for the caching
  • Using a NSAutoreleasePool for the caching part.
  • Only caching the row ID & mac 4 fields necesary to show the cell data
  • UIView made with interface builder, SDK 2.2.1
  • Instruments say I use 2.5 MB in the device

解决方案

The -[FMResultSet next] call can be a very expensive call to make, depending on the data that's getting loaded. It'd during this call that sqlite is actually going to the database, finding the next row to return, and giving you back the appropriate fields. It's not just an enumerator.

You might want to consider pre-caching all of the data before actually displaying the table. This means that you would do all of your FMDB calls before the table gets shown on the screen.

If that takes too long, you might want to show the tableview with its initial rows, and then use NSOperations or just a second thread to load the data in the background and cache it that way.

这篇关于UITableView的加载缓慢.怎么知道为什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆