I am facing problem in my app - you can post and edit your favorite places. After posting a post, or editing a specific post (UITableViewCell
), UITableview
is reloaded.
My problem is: the UITableview
scrolls to the top after reloading. But that's not what I want. I want my view to stay on the cell / view where I was. But I don't know how to manage that.
Could you help me?
To prevent scrolling to top, you should save heights of cells when they loads and give exact value in
tableView:estimatedHeightForRowAtIndexPath
:Just go for these lines if you want an easy solution
In swift 3.1
The
UITableView
'sreloadData()
method is explicitly a force reload of the entire tableView. It works well, but is usually jarring and a bad user experience if you're going to do that with a tableview that the user is currently looking at.Instead, take a look at
reloadRowsAtIndexPaths(_:withRowAnimation:)
andreloadSections(_:withRowAnimation:)
in the documentation.Igor's answer is correct if you are using dynamically resizable cells (UITableViewAutomaticDimension)
Here it is in swift 3: