UITableView scroll to bottom from current position

Viewed 6956

How can I scroll to last row in tableview from current positon, because I have tried this solution:

self.tableView.scrollToRow(at: lastIndex.last!, at: .bottom , animated: false)


let numberOfSections = self.tableView.numberOfSections
            let numberOfRows = self.tableView.numberOfRows(inSection: numberOfSections-1)

        if numberOfRows > 0 {
            let indexPath = IndexPath(row: numberOfRows-1, section: (numberOfSections-1))
            self.tableView.scrollToRow(at: indexPath, at: .bottom, animated: animated)
        }

and it doesn't scroll from the current position but from the most top position. Even though my current position is the last row

4 Answers

For swift 4

func scrollToLastRow() {

    if CommentNameArray.count != 0 {
        let indexPath = NSIndexPath(row: CommentNameArray.count - 1, section: 0)
        self.CommentTableView.scrollToRow(at: indexPath as IndexPath, at: .bottom, animated: true)
    }

}
Related