From b768877e23bf5375b94d4a51fe74a8740e5cfbf0 Mon Sep 17 00:00:00 2001 From: Maurice Parker Date: Mon, 2 Sep 2019 12:40:14 -0500 Subject: [PATCH] Use correct delegate methods to begin and end searching --- .../MasterTimelineViewController.swift | 29 ++++++++++--------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/iOS/MasterTimeline/MasterTimelineViewController.swift b/iOS/MasterTimeline/MasterTimelineViewController.swift index d6f290ee5..bd9196ffc 100644 --- a/iOS/MasterTimeline/MasterTimelineViewController.swift +++ b/iOS/MasterTimeline/MasterTimelineViewController.swift @@ -42,6 +42,7 @@ class MasterTimelineViewController: UITableViewController, UndoableCommandRunner NotificationCenter.default.addObserver(self, selector: #selector(contentSizeCategoryDidChange), name: UIContentSizeCategory.didChangeNotification, object: nil) // Setup the Search Controller + searchController.delegate = self searchController.searchResultsUpdater = self searchController.obscuresBackgroundDuringPresentation = false searchController.searchBar.delegate = self @@ -415,6 +416,20 @@ class MasterTimelineViewController: UITableViewController, UndoableCommandRunner // MARK: Searching +extension MasterTimelineViewController: UISearchControllerDelegate { + + func willPresentSearchController(_ searchController: UISearchController) { + coordinator.beginSearching() + searchController.searchBar.showsScopeBar = true + } + + func willDismissSearchController(_ searchController: UISearchController) { + coordinator.endSearching() + searchController.searchBar.showsScopeBar = false + } + +} + extension MasterTimelineViewController: UISearchResultsUpdating { func updateSearchResults(for searchController: UISearchController) { @@ -425,24 +440,10 @@ extension MasterTimelineViewController: UISearchResultsUpdating { } extension MasterTimelineViewController: UISearchBarDelegate { - func searchBar(_ searchBar: UISearchBar, selectedScopeButtonIndexDidChange selectedScope: Int) { let searchScope = SearchScope(rawValue: selectedScope)! coordinator.searchArticles(searchBar.text!, searchScope) } - - func searchBarShouldBeginEditing(_ searchBar: UISearchBar) -> Bool { - coordinator.beginSearching() - searchBar.showsScopeBar = true - return true - } - - func searchBarShouldEndEditing(_ searchBar: UISearchBar) -> Bool { - coordinator.endSearching() - searchBar.showsScopeBar = false - return true - } - } // MARK: Private