There are one to three UITableViewCells in a UITableViewView. Is there a way to always position the cell(s) at the bottom of screen after rel
func updateContentInsetForTableView( tableView:UITableView,animated:Bool) {
let lastRow = tableView.numberOfRows(inSection: 0)
let lastIndex = lastRow > 0 ? lastRow - 1 : 0;
let lastIndexPath = IndexPath(row: lastIndex, section: 9)
let lastCellFrame = tableView.rectForRow(at: lastIndexPath)
let topInset = max(tableView.frame.height - lastCellFrame.origin.y - lastCellFrame.height, 0)
var contentInset = tableView.contentInset;
contentInset.top = topInset;
_ = UIViewAnimationOptions.beginFromCurrentState;
UIView.animate(withDuration: 0.1, animations: { () -> Void in
tableView.contentInset = contentInset;
})
if self.commesnts.count > 0 {
tableView.scrollToRow(at: IndexPath(item:self.commesnts.count-1, section: 0), at: .bottom, animated: true)
}
}
I used @bkokot solution with little addition. It does two things
1. Start showing cells from bottom of UITableView
2. Scroll cells to bottom so that last inserted row become visible
(just like chat)