0

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.

rmaddy
  • 314,917
  • 42
  • 532
  • 579
alionthego
  • 8,508
  • 9
  • 52
  • 125
  • 1
    Could be SLC. Try to scroll to the bottom during will appear rather than viewdidload. – stevenpcurtis Apr 29 '18 at 02:14
  • what is SLC? I tried in viewWillAppear but same result. Only partially scrolled. – alionthego Apr 29 '18 at 04:04
  • Possible duplicate of [Scroll all the way down to the bottom of UITableView](https://stackoverflow.com/questions/38886817/scroll-all-the-way-down-to-the-bottom-of-uitableview) – rbaldwin Apr 29 '18 at 06:24

0 Answers0