如果用的时NSArray或者NSDictionary来标识Section和Row数量,请在调用增删方法时更新好数据。并且在beginUpdate和 enUpdate方法中间增删操作。
self.tableView.beginUpdates()
//数组元素+1
self.lists.append(self.lists.count+1)
//底部插入一行数据
let bottomIndexPath = IndexPath.init(row: self.lists.count-1, section: 0)
let insertIndexPaths = Array.init(arrayLiteral: bottomIndexPath)
//同样,将数据加到数据列表后刷新
self.tableView.insertRows(at: insertIndexPaths, with: .automatic)
self.tableView.endUpdates()
//滚动位置
self.tableView.scrollToRow(at: bottomIndexPath, at: .bottom, animated: true)