Upon first presenting my tableView controller I load data into my model array and then scroll the tableView to the bottom. However the tableView does not scroll all the way down. Just scrolls to an intermediate position. Subsequent scrolling using the same method always correctly scrolls to the bottom.
I have the following code in my viewDidLoad of the tableViewController:
override func viewDidLoad() {
super.viewDidLoad()
let fetchRequest: NSFetchRequest<Item> = NSFetchRequest(entityName: "Item")
do {
let fetchedResults = try context.fetch(fetchRequest)
if fetchedResults.count > 0 {
self.dataArray = fetchedResults
let indexPath = IndexPath(item: (dataArray.count - 1), section: 0)
self.tableView.scrollToRow(at: indexPath, at: UITableViewScrollPosition.bottom, animated: false)
}
} catch {
print("Could not fetch \(error)")
}
}
I am using an inputAccessoryView in my tableViewController. Additionally I am using automaticDimensions although I did try calculating each row height and it didn't make any difference.
Wondering why the tableView is scrolling to an arbitrary intermediate position and not the bottom. On all subsequent scrollToRowAt calls, the tableView correctly scrolls to the bottom.