         }
     }
     
-    func segmentedControlChanged() {
+    enum ViewMode {
+        case map
+        case list
+        case search
+    }
+    
+    var viewMode: ViewMode = .map {
+        didSet {
+            if oldValue == .search && viewMode != .search {
+                navigationItem.setRightBarButton(segmentedControlBarButtonItem, animated: true)
+            } else if oldValue != .search && viewMode == .search {
+                navigationItem.setRightBarButton(closeBarButtonItem, animated: true)
+            }
+            switch viewMode {
+            case .list:
+                deselectAllAnnotations()
+                updateDistanceFromUserOnVisibleCells()
+                mapView.isHidden = true
+                listView.isHidden = false
+                searchSuggestionView.isHidden = true
+            case .search:
+                mapView.isHidden = true
+                listView.isHidden = true
+                searchSuggestionView.isHidden = false
+            case .map:
+                fallthrough
+            default:
+                mapView.isHidden = false
+                listView.isHidden = true
+                searchSuggestionView.isHidden = true
+            }
+            recenterOnUserLocationButton.isHidden = mapView.isHidden
+            redoSearchButton.isHidden = mapView.isHidden
+        }
+    }
+    
+    func updateViewModeFromSegmentedControl() {
         switch segmentedControl.selectedSegmentIndex {
         case 0:
-            listView.isHidden = true
+            viewMode = .map
         default:
-            deselectAllAnnotations()
-            listView.isHidden = false
-            updateDistanceFromUserOnVisibleCells()
+            viewMode = .list
         }
     }
     

        segmentedControl = UISegmentedControl(items: [map, list])
        
        segmentedControl.selectedSegmentIndex = 0
        segmentedControl.addTarget(self, action: #selector(segmentedControlChanged), for: .valueChanged)
        segmentedControl.tintColor = UIColor.wmf_blueTint()
        segmentedControlBarButtonItem = UIBarButtonItem(customView: segmentedControl)
        navigationItem.rightBarButtonItem = segmentedControlBarButtonItem

    }
    
    func searchBarTextDidEndEditing(_ searchBar: UISearchBar) {
        updateViewModeFromSegmentedControl()
    }
    
    // MARK: UITableViewDataSource
