UITableView scroll issue on reload or during update/edit any post.

Many developers are facing this problem that whenever they reload UITableView it scrolls up, or whenever they edit the post and reload UITableView again it scrolls up. There are two simple fixes of this issue.

When the height of the row is fixed

When your height of the row is fixed, then it is pretty simple. Follow the below steps.
– Open your Storyboard and select UITableView in your Xib.
– Now open Size Inspector of UITableView.
– In the first section that is Table View enter the fixed Row Height and Estimated height and uncheck both the Automatic box. After making above changes your Xib will be look like below.

When the height of the row is dynamic

When the height of the row is dynamic we will try a different way. We will use beginUpdates() and endUpdates() functions. Instead of reloading UITableView use below piece of code.


let contentOffSet = self.tableView.contentOffset
self.tableView.beginUpdates()
/* --- Add your code here --- */
self.tableView.endUpdates()
self.tableView.layer.removeAllAnimations()
self.tableView.setContentOffset(contentOffSet, animated: false)

Hopefully, this will solve your problem.

Leave a Reply

Your email address will not be published. Required fields are marked *