shannoga shannoga - 3 months ago 46
iOS Question

Reload tableview section without scroll or animation

I am reloading a tableView section using this code -

self.tableView.beginUpdates()
self.tableView.reloadSections(NSIndexSet(index: 1), withRowAnimation: UITableViewRowAnimation.None)
self.tableView.endUpdates()


Still the rows replacement is animated and the table view scrolls to the top.

How can I make sure that no animation will be applied to the section reload + prevent the table view from scrolling.

Thanks

Answer

Try this:

UIView.setAnimationsEnabled(false)
self.tableView.beginUpdates()
self.tableView.reloadSections(NSIndexSet(index: 1), withRowAnimation: UITableViewRowAnimation.None)
self.tableView.endUpdates()
UIView.setAnimationsEnabled(true)