UITableView choppy pagination
Have you ever implemented UITableView
infinite scrolling or pagination in combination with the UIRefreshControl
and the scrolling somehow stopped or was laggy right when you were inserting new rows? I was puzzled that this was not happening in all cases and couldn’t figure out what’s causing it.
After a bit of investigation, it turns out a piece of the puzzle was a UIRefreshControl
bound to the table view. If the table view had no refresh control, everything was running smoothly. More specifically, (after lots of trial and error) I found that it’s the endRefreshing()
method of the refresh control that stops table view scrolling. I was calling this method whenever new data/page was fetched and before I inserted new rows or reloaded the table. I haven’t checked but my guess is that endRefreshing
tries to restore the content offset that was changed when starting refresh and that causes table view to stop scrolling.
Anyway, the fix for this is, obviously, trivial:
if refreshControl.isRefreshing {
refreshControl.endRefreshing()
}