Browse Source

Merge pull request #1198 from deltachat/fix-scrollToBottom

on scrollToRow(), check the real number of rows
bjoern 4 years ago
parent
commit
2e6b73998a
1 changed files with 4 additions and 1 deletions
  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)
+                }
             }
         }
     }