0

I am trying to write a function that scrolls to the bottom cell of a given section in my tableView, I'm calling this function after my tableView.reloadData() function but it is not scrolling, any ideas why?

func scrollToBottom(section: Int){
        DispatchQueue.main.async {
            let indexPath = IndexPath(row: self.session[section].count - 1, section: section)
            self.tableView.scrollToRow(at: indexPath, at: .bottom, animated: true)
        }
    }
Noah Iarrobino
  • 1,435
  • 1
  • 10
  • 31

1 Answers1

0

You don't need put code in DispatchQueue.main because it already run on main thread.

Try this

func scrollToBottom(section: Int){
        let indexPath = IndexPath(row: self.session[section].count - 1, section: section)
        self.tableView.scrollToRow(at: indexPath, at: .top, animated: true)
    }
HHumorous
  • 174
  • 1
  • 11