From 979fcbc013adcfd426f2d61e9ed1aec7747f02bc Mon Sep 17 00:00:00 2001 From: Maurice Parker Date: Thu, 12 Sep 2019 13:49:23 -0500 Subject: [PATCH] Don't update feed selection for zero rows. --- iOS/MasterFeed/MasterFeedViewController.swift | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/iOS/MasterFeed/MasterFeedViewController.swift b/iOS/MasterFeed/MasterFeedViewController.swift index 94e14c63a..03b7de0f4 100644 --- a/iOS/MasterFeed/MasterFeedViewController.swift +++ b/iOS/MasterFeed/MasterFeedViewController.swift @@ -452,12 +452,14 @@ class MasterFeedViewController: UITableViewController, UndoableCommandRunner { } func updateFeedSelection() { - if let indexPath = coordinator.currentFeedIndexPath { - if tableView.indexPathForSelectedRow != indexPath { - tableView.selectRowAndScrollIfNotVisible(at: indexPath, animated: true, deselect: coordinator.isRootSplitCollapsed) + if dataSource.snapshot().numberOfItems > 0 { + if let indexPath = coordinator.currentFeedIndexPath { + if tableView.indexPathForSelectedRow != indexPath { + tableView.selectRowAndScrollIfNotVisible(at: indexPath, animated: true, deselect: coordinator.isRootSplitCollapsed) + } + } else { + tableView.selectRow(at: nil, animated: true, scrollPosition: .none) } - } else { - tableView.selectRow(at: nil, animated: true, scrollPosition: .none) } } @@ -495,7 +497,7 @@ class MasterFeedViewController: UITableViewController, UndoableCommandRunner { } if let indexPath = dataSource.indexPath(for: node) { - tableView.scrollToRow(at: indexPath, at: .middle, animated: true) + tableView.selectRowAndScrollIfNotVisible(at: indexPath, animated: true) coordinator.selectFeed(indexPath) completion?() return