UITableView takes a lot longer when numberOfRows returns a large number

Why does a UITableView take longer to load when the number of rows is large? Why does it take time between viewDidLoad and the first call to the cellForRowAtIndexPath function?

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

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 10000 (note 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 
+2
source share
1 answer

If you implement heightForRowAtIndexPath: in your table view, then iOS will go and check the height of each cell, I think, to draw a scroll bar. Therefore, it is worth making this call very quick, if possible.

If you support iOS 7, consider implementing tableView: estimatedHeightForRowAtIndexPath: which can simply return a constant (or maybe very fast logic) to guess at a height. This will be delayed when calling heightForRowAtIndexPath: until the cell is scanned and should not greatly accelerate the work.

0
source

Source: https://habr.com/ru/post/894056/


All Articles