From 978aeeee801c0d8708e254b5a0153bdc4d3392ca Mon Sep 17 00:00:00 2001 From: Maurice Parker Date: Sat, 27 Jul 2019 15:05:21 -0500 Subject: [PATCH] Restore selection when currently select feed unread count changes --- iOS/MasterFeed/MasterFeedViewController.swift | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/iOS/MasterFeed/MasterFeedViewController.swift b/iOS/MasterFeed/MasterFeedViewController.swift index fd49d3b90..9d1234d63 100644 --- a/iOS/MasterFeed/MasterFeedViewController.swift +++ b/iOS/MasterFeed/MasterFeedViewController.swift @@ -103,7 +103,9 @@ class MasterFeedViewController: UITableViewController, UndoableCommandRunner { return } - tableView.reloadRows(at: [indexPath], with: .automatic) + performBlockAndRestoreSelection { + tableView.reloadRows(at: [indexPath], with: .automatic) + } } @@ -672,4 +674,12 @@ private extension MasterFeedViewController { } } + func performBlockAndRestoreSelection(_ block: (() -> Void)) { + let indexPaths = tableView.indexPathsForSelectedRows + block() + indexPaths?.forEach { [weak self] indexPath in + self?.tableView.selectRow(at: indexPath, animated: false, scrollPosition: .none) + } + } + }