I am writing a table view where rows are added when interacting with the user. The general behavior is to simply add one line, then scroll to the end.
This worked fine before iOS11, but now scrolling always jumps from the top of the table, rather than scrolling smoothly.
Here is the code that is associated with adding newlines:
func updateLastRow() {
DispatchQueue.main.async {
let lastIndexPath = IndexPath(row: self.currentSteps.count - 1, section: 0)
self.tableView.beginUpdates()
self.tableView.insertRows(at: [lastIndexPath], with: .none)
self.adjustInsets()
self.tableView.endUpdates()
self.tableView.scrollToRow(at: lastIndexPath,
at: UITableViewScrollPosition.none,
animated: true)
}
}
and
func adjustInsets() {
let tableHeight = self.tableView.frame.height + 20
let table40pcHeight = tableHeight / 100 * 40
let bottomInset = tableHeight - table40pcHeight - self.loadedCells.last!.frame.height
let topInset = table40pcHeight
self.tableView.contentInset = UIEdgeInsetsMake(topInset, 0, bottomInset, 0)
}
I am sure that the error is that several user interface updates are added at the same time (adding lines and repeated computations of the insert) and they tried to associate these functions with individual objects CATransaction
, but this completely blocks asynchronous terminating blocks defined elsewhere in the code, which update some cell user interface elements.
:)