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.
You can use self. tableView. reloadData() in order to reload your entire table or self.
reloadData()Reloads the rows and sections of the table view.
To scroll to the top of our tableview we need to create a new IndexPath . This index path has two arguments, row and section . All we want to do is scroll to the top of the table view, therefore we pass 0 for the row argument and 0 for the section argument. UITableView has the scrollToRow method built in.
To prevent scrolling and animation, do this:
UIView.performWithoutAnimation { let loc = tableView.contentOffset tableView.reloadRows(at: [indexPath], with: .none) tableView.contentOffset = loc }
Swift 4:
Actually, the best way to prevent crazy animation during scrolling or expand/collapse cells is:
UIView.performWithoutAnimation { self.tableView.reloadRows(at: [indexPath], with: .none) }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With