Validate that the selected row hasn't been removed when trying to select or scroll to it. Issue #1976

This commit is contained in:
Maurice Parker 2020-04-22 18:18:20 -05:00
parent 82e7d4eaf0
commit a5583fc655

View File

@ -14,6 +14,13 @@ extension UITableView {
Selects a row and scrolls it to the middle if it is not visible Selects a row and scrolls it to the middle if it is not visible
*/ */
public func selectRowAndScrollIfNotVisible(at indexPath: IndexPath, animations: Animations) { public func selectRowAndScrollIfNotVisible(at indexPath: IndexPath, animations: Animations) {
guard let dataSource = dataSource,
let numberOfSections = dataSource.numberOfSections,
indexPath.section < numberOfSections(self),
indexPath.row < dataSource.tableView(self, numberOfRowsInSection: indexPath.section) else {
return
}
selectRow(at: indexPath, animated: animations.contains(.select), scrollPosition: .none) selectRow(at: indexPath, animated: animations.contains(.select), scrollPosition: .none)
if let visibleIndexPaths = indexPathsForRows(in: safeAreaLayoutGuide.layoutFrame) { if let visibleIndexPaths = indexPathsForRows(in: safeAreaLayoutGuide.layoutFrame) {