Snapping issues when reloading the tableView
Hello Simon!
Nice repo, it's working great and I like it.
I've been using the same approach in one of the projects I've been working on and it turns out that there's one problem I'd like to talk to you about. This solution works very well as the tableView is static. However, if you have to reload the tableView at some point during the scrolling animation, it can lead to unexpected visual bugs. In order to reproduce the issue, the following conditions should be met:
- The data in the
tableViewshould change (i.e. set a different number of rows) reloadDatashould be called during the scrolling animation
As the result, one of the following can happen:
- (rare)
tableViewstops scrolling and itscontentOffsetis stuck in between the two snapping points; - (common)
tableViewabruptly jumps back to its previous position or to zero offset
Here it is visualized:

The obvious solution that comes to mind is to defer the reloading until the moment the scrolling is finished, e.g. call reloadData at scrollViewDidEndDecelerating or scrollViewDidEndScrollingAnimation, but I've tried this and it still won't work.
I would like to know if you have any ideas on this topic.
Cheers!
Hey, thanks a lot for this well written issue! Sorry for not getting back sooner. I unfortunately don't have any suggestions at this time. In the app where I used this technique, we had no need to reload the data. The only idea I can think of is what you already wrote, to wait for did end decelerating or similar. Weird that it doesn't work.
I hope to get around writing a follow-up blog post at some point and mention problems with this approach, I'll be sure to mention this then.