UITableView的reloadData有多昂贵? [英] How expensive is UITableView's reloadData?

查看:174
本文介绍了UITableView的reloadData有多昂贵?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我很好奇,就资源去说是多么昂贵的是UITableView的reloadData?我有一个应用程序,将大约10个后续的HTTP请求,当它获取数据/ preps,它重新加载tableView。随着数据集越来越大,它变得非常缓慢。我想弄清楚是否是因为我重新加载tableView的次数,或者因为我如何抓取/解析数据。



什么是在这种情况下的最佳实践?

解决方案

最好的做法是让你的实现 cellForRowAtIndexPath: / code>尽可能少的工作。事实上,除了用需要显示的数据填充 UITableViewCell 实例,它实际上不应该做任何工作。



您应该使用缓存 UITableViewCell ,这样您就不必每次都分配一个新的单元格。如果你可以在一个单独的线程中进行解析等操作,并准备提供给 cellForRowAtIndexPath:的解析数据,则不应该有任何性能问题。 / p>

你没有说你是否使用了自定义的 UITableViewCell 子类,但如果你是,也呈现性能问题,因为层次结构中的每个视图都会被绘制。你可以让 UITableViewCell 更好。



希望你能朝正确的方向移动。 / p>

I'm curious just how expensive in as far as resources go is UITableView's reloadData? I have an app which will make roughly 10 subsequent HTTP requests, and as it gets data / preps, it reloads the tableView. As the data set grows larger and larger, it's becoming very sluggish. I'm trying to figure out if it's because of the amount of times I'm reloading the tableView or because of how I'm grabbing/parsing the data.

What's the best practice in this case?

解决方案

The best practice is to have your implementation of cellForRowAtIndexPath: do as little work as possible. In fact, it really shouldn't be doing any work except populating the UITableViewCell instance with the data it needs to display.

You should be using cached UITableViewCells so you don't have to allocate a new cell each time. If you can do your parsing and such in a separate thread and make the parsed data, ready to present, accessible to cellForRowAtIndexPath:, you shouldn't have any performance problems.

You didn't say if you were using a custom UITableViewCell subclass, but if you are, deep view hierarchies can also present a performance problem, since each view in the hierarchy gets drawn. The flatter you can make UITableViewCells, the better.

Hope that gets you moving in the right direction.

这篇关于UITableView的reloadData有多昂贵?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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