Sean Cook Sean Cook - 1 year ago 82
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 Source

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)