0

I am having a requirement in an app where almost each uitableviewcell is having different height. Also, many cells have Images (1,2 or 3) with text.

Earlier I was using the heightForRowAtIndexpath but as usual, the performance was very pathetic with jerky feel,

I did following to resolve the issue,

  1. Implemented estimatedHeightForRowAtIndexPath
  2. Used cache for the calculated height for subsequent calls to estimatedHeightForRowAtIndexPath
  3. Using autolayout in all the cells.

With this the Performance is much better, as compared to previous approach, but, the estimatedHeightForRowAtIndexPath is called so many times subsequently due to which the list is jerky.

If the cell number N is loaded, the estimatedHeightForRowAtIndexPath is called N-1 times, and this happens if we go further in list, if we go backward it knows the estimated height.

Please help me understand why this happens and what can I do to increase the performance and make the scroll Jerk-less and smooth.

infiniteLoop
  • 2,135
  • 1
  • 25
  • 29

2 Answers2

1

To make the table smooth, i use this strategy..

  1. Whenever i populate my tableView data source, i calculate height of each cell. I store the height for each cell in an array cellHeights
  2. In heightforRowAtIndexPath, i return cellHeights[indexPath.row]

The resulting transition has always been super smooth :)

0

Instead of blaming the framework for sending you the messages "too often", you should blame your own code for not responding fast enough. You say:

Earlier I was using the heightForRowAtIndexpath but as usual, the performance was very pathetic with jerky feel

But your "as usual" is wrong. If you can't return the result from heightForRowAtIndexPath: instantly, then your implementation of this method is wrong. You should be "memoizing" your height calculations so that, having calculated a row's height once, you know its height forever after.

matt
  • 515,959
  • 87
  • 875
  • 1,141
  • Well, i am not at all using 'heightforrow...' And we shouldn't if we want to completely rely on autolayout. estimated height is specifically to get rid of calculating height explicitly. As I said my cells height constantly changes and has many subviews with images and texts. Also, my question is related to 'why its calling so many times' as this is the culprit and it gives jerky behaviour. Once all heights are known to table view its smooth as butter. – infiniteLoop Jan 22 '16 at 23:52