Don't crash when scrolling to the oldest item before the data is applied

scrollToOldestItem targeted (timelineItemsIDs.count - 1, section: 1) even
when the table's data source hadn't applied that section yet, raising an
out-of-bounds NSRangeException. Scroll against the table's actual section
and row counts instead.
This commit is contained in:
Stefan Ceriu
2026-06-22 14:33:12 +03:00
parent 0a3944deaa
commit d40d775717
@@ -420,10 +420,13 @@ class TimelineTableViewController: UIViewController {
/// Scrolls to the oldest item in the timeline.
private func scrollToOldestItem(animated: Bool) {
guard !timelineItemsIDs.isEmpty else {
// The data source can lag behind timelineItemsIDs, so scroll against the table's actual
// contents to avoid targeting a section or row that doesn't exist yet.
guard tableView.numberOfSections > 1,
tableView.numberOfRows(inSection: 1) > 0 else {
return
}
tableView.scrollToRow(at: IndexPath(item: timelineItemsIDs.count - 1, section: 1), at: .bottom, animated: animated)
tableView.scrollToRow(at: IndexPath(item: tableView.numberOfRows(inSection: 1) - 1, section: 1), at: .bottom, animated: animated)
scrollDirectionPublisher.send(.top)
}