Reputation: 11780
I have a design consisting of a TextField, a Button, and a TableView. The user enters a text in the TextField, then clicks the Button which launches a search. When the result returns from the server, the result is shown in the TableView.
Instead of a TextField and a Button, I want to use the SearchBar. I am not clear how to do that. Every tutorial and example I can find talk of UISearchBar and UISearchDisplayController, as if the two were inseparable. I only want to use the SearchBar to launch an internet search — with quite truly no connection to the TableView: it’s just incidental that I am displaying the data through a TableView. So how do I make the switch from “TextField and Button” to SearchBar? I imagine all I need is to implement searchBarSearchButtonClicked
. But is that sound design? I mean, why do people always use UISearchDisplayController? What is UISearchDisplayController anyway? I don’t quite get its value.
Upvotes: 1
Views: 872
Reputation: 10045
You don't have to use UISearchDisplayController
- that is merely a "convenience" construction that combines a tableview with "No Results" message, a search bar and a couple of neat animations. You have two possible choices of how you can make search happen via UISearchBar
- either send an asynchronous search request every time a new character is inputted into your search bar, while canceling previous search requests to not to receive their callbacks - which is costly from server-side perspective, but pretty neat from usability standpoint or use the approach you've described - perform search upon the searchBarSearchButtonClicked
event.
Upvotes: 1