فهرست منبع

on scrollToRow(), check the real number of rows

messageIds.count may be out of sync;
it is probably okay to check that to avoid update,
but when the update is actually done,
we cannot scroll to a row that is not there
(otherwise, we get a crash)
B. Petersen 4 سال پیش
والد
کامیت
e8abb90ec4
1فایلهای تغییر یافته به همراه4 افزوده شده و 1 حذف شده
  1. 4 1
      deltachat-ios/Chat/ChatViewController.swift

+ 4 - 1
deltachat-ios/Chat/ChatViewController.swift

@@ -757,7 +757,10 @@ class ChatViewController: UITableViewController {
         if !messageIds.isEmpty {
             DispatchQueue.main.async { [weak self] in
                 guard let self = self else { return }
-                self.tableView.scrollToRow(at: IndexPath(row: self.messageIds.count - 1, section: 0), at: .bottom, animated: animated)
+                let numberOfRows = self.tableView.numberOfRows(inSection: 0)
+                if numberOfRows > 0 {
+                    self.tableView.scrollToRow(at: IndexPath(row: numberOfRows - 1, section: 0), at: .bottom, animated: animated)
+                }
             }
         }
     }