Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Implementing estimatedHeightForRowAtIndexPath: causes the tableView to scroll down while reloading

I've implemented 'infinite scrolling' on one of my projects and I was playing around with the new estimatedHeightForRowAtIndexPath: delegate method. Once I implemented that delegate method, my tableView jumps (a.k.a scroll to the bottom) whenever i call reloadData (which happens when i add a new set of rows.)

Without that method, my tableView stays in place and it adds the additional rows to the bottom of the tableView without any scrolling.

I'm calling the [tableView reloadData] and not the other methods (insertRowsAtIndexPaths:). I don't call the beginUpdates or endUpdates since I'm reloading the whole table.

Has anyone experienced this ? I

like image 204
newDeveloper Avatar asked Jul 16 '26 21:07

newDeveloper


2 Answers

So here's what i did to reduce the jumping while reloading the tableView.

In the estimatedHeightForRowAtIndexPath: I started returning a better estimated height. The more accurate the height is, lesser the jumping while adding new rows to the bottom.

I also started caching the calculated height of the cell from heightForRowAtIndexPath: in a dictionary and return the cached value the next time it calls the estimatedHeightForRowAtIndexPath:.

Hope this helps anyone who encounters this issue.

like image 136
newDeveloper Avatar answered Jul 19 '26 10:07

newDeveloper


I filed a BugReport quite a while ago (16472265) and today got the response that it's fixed in iOS8. Tried it out and it works now as expected. No more jumping of the tableview! Wohoooo

like image 28
Georg Avatar answered Jul 19 '26 10:07

Georg



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!