lastReturn數據只會在下一次進入聊天界面的時候才會向上移動??
方法① : 代碼是用contentSize
的方式寫的 , 就出現了上面的??情況 ;
方法② : 使用scrollToRow:
點擊return之后,數據就會刷新, 數組就會多加一個數據 , 通過判斷 (最新數據的個數 -1 ) 就是scrollVIew要跳轉的行數
執行跳轉:
滾動到最新消息位置
func scrollToBottom(_ scrollView:UIScrollView,animated:Bool) {
//FIXME: 之前用到contentSize 和 bounds 的高度差來移動,最新的數據總是會在下一次才上移
if self.chatMsgs.count == 0 {
return
}
let lastIndexPath = IndexPath(row: self.chatMsgs.count - 1, section: 0)
self.tableView?.scrollToRow(at: lastIndexPath, at: UITableViewScrollPosition.bottom, animated: true)
}