I am reloading a tableView section using this code -
self.tableView.beginUpdates()
self.tableView.reloadSections(NSIndexSet(index: 1), withRowAnimation: UITa
Neither of given answers worked for me. Here's the solution I found, hope it would be useful to someone
Swift 4:
let lastScrollOffset = tableView.contentOffset
tableView.beginUpdates()
tableView.reloadSections(IndexSet(integer: 1), with: .none)
tableView.endUpdates()
tableView.layer.removeAllAnimations()
tableView.setContentOffset(lastScrollOffset, animated: false)
To prevent scrolling and animation, do this:
UIView.performWithoutAnimation {
let loc = tableView.contentOffset
tableView.reloadRows(at: [indexPath], with: .none)
tableView.contentOffset = loc
}
Add one line more to this method in viewDidLoad
self.tableView.remembersLastFocusedIndexPath = true
Add this code where you want refresh after updation
UIView.setAnimationsEnabled(false)
self.tableView.beginUpdates()
self.tableView.reloadSections(NSIndexSet(index: 1) as IndexSet, with: UITableViewRowAnimation.none)
self.tableView.endUpdates()
Swift 5
UIView.performWithoutAnimation {
self.tableView.reloadRows(at: [indexPath], with: .none)
}
Try this:
UIView.setAnimationsEnabled(false)
self.tableView.beginUpdates()
self.tableView.reloadSections(NSIndexSet(index: 1) as IndexSet, with: UITableViewRowAnimation.none)
self.tableView.endUpdates()
I've had this problem too. It seems to stem from putting an IndexPath inside .reloadSections instead of a IndexSet as it requests. Which is why it seems to work with .reloadRows with out issue:
tableView.reloadRows(at: [IndexPath], with: UITableView.RowAnimation)
tableView.reloadSections(IndexSet, with: UITableView.RowAnimation)
Just wrap the section you want to reload as an IndexSet:
tableView.reloadSections(IndexSet(integer: sectionInt), with: .none)