UITableView takes much longer to load when numberOfRows returns a large number

余生长醉 提交于 2019-12-24 05:46:22

问题


Why does UITableView take more time to load when the number of rows is large? What is it that takes time between viewDidLoad and the first cellForRowAtIndexPath function call?

These are the log statements when numberOfRows returns 100,000 (notice the time (5 seconds delay)):

2014-02-05 20:51:22.806 TableViewTest[3995:60b] View Did Load
2014-02-05 20:51:27.526 TableViewTest[3995:60b] Cell for row at indexpath.row: 0

These are the log statements when numberOfRows returns 10,000 (notice the time (1 second delay)):

2014-02-05 20:54:50.793 TableViewTest[4007:60b] View Did Load
2014-02-05 20:54:51.846 TableViewTest[4007:60b] Cell for row at indexpath.row: 0

回答1:


If you implement heightForRowAtIndexPath: in your table view, then iOS will go and check the height of each cell, I think to draw the scroll bar. So it's worth it to make that call very fast if possible.

If you are supporting iOS 7, then consider implementing tableView: estimatedHeightForRowAtIndexPath: which can just return a constant (or maybe very quick logic) to guess at the height. This will delay when heightForRowAtIndexPath: is called until right before the cell is actually viewed and should speed things up a lot.



来源:https://stackoverflow.com/questions/21577976/uitableview-takes-much-longer-to-load-when-numberofrows-returns-a-large-number

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!