Sean Cook Sean Cook - 4 months ago 6
Swift Question

Swift scroll to bottom of table that has only blank sections

I am trying to scroll my table to the bottom every time a new section is added. They section may or may not have any rows but it still needs to scroll to the bottom. Any way to do this?

Answer

You may try something like this:

func scrollToBottom() {
    let bottomOffset = CGPoint(x: 0, y: tableView.contentSize.height - tableView.bounds.size.height + tableView.contentInset.bottom);
    tableView.setContentOffset(bottomOffset, animated: true)
}
Comments