The behavior that you expect is logical and seems right at first glance, but in fact it is not. Fortunately, there is an easy workaround.
Here is the description of the Apple method:
Called when the search bar becomes the first responder or when a user makes changes to the search bar.
Changing an area is a change in the search bar, right? It makes sense to me. But if you read the discussion , Apple makes it clear that the behavior is not what you expect:
This method is automatically called whenever the search bar becomes the first responder or we enter text into the search bar.
Not included: changes in the field. Itβs strange not to notice, is it? Either the method should be called when the scope is changed, or it should be clear in the summary that this is not so.
You can get the behavior you searchController.searchBar.delegate adding the UISearchBarDelegate protocol to your view controller and setting searchController.searchBar.delegate to your view controller.
Then add the following:
func searchBar(searchBar: UISearchBar, selectedScopeButtonIndexDidChange selectedScope: Int) { updateSearchResultsForSearchController(searchController) }
This will cause updateSearchResultsForSearchController to run when the scope changes as you expect. But instead, you may need to change the meat of updateSearchResultsForSearchController to a new method that calls both the updateSearchResultsForSearchController and selectedScopeButtonIndexDidChange calls.
source share