1

I have a huge list of elements, and only 50 is shown in table view through API paging. There is a search bar with the table view. When someone searches using the search bar, I need to use a search API. Is there a way to make this just like normal search experience as you would search through the table view elements per key press.

  • What is a "normal search experience" ? Are you trying to search only the loaded elements, or all elements? – Connor Aug 18 '17 at 16:39
  • UISearchBar contains it's delegate you can use that delegate to call your search service. here it is [link](https://developer.apple.com/documentation/uikit/uisearchbardelegate) – Maulik Pandya Aug 18 '17 at 16:45
  • By normal search experience I meant using array.filter() over local data source on didChangeSearchText(). And I am trying to search over all elements using API call. – Twaha Mukammel Aug 18 '17 at 16:48
  • [This](https://stackoverflow.com/questions/24330056/how-to-throttle-search-based-on-typing-speed-in-ios-uisearchbar) might help – Hooda Aug 18 '17 at 16:51
  • from delegate didChangeSearchText(), calling the service may be not a good idea - so many API calls?! – Twaha Mukammel Aug 18 '17 at 16:51
  • 1
    You can use search bar text did change method and perform an API call for search text characters count is multiple is 3 like `if ([searchText length] % 3 == 0) { //Perform API }` – Febin Fathah Aug 18 '17 at 16:52
  • I found [this](https://stackoverflow.com/questions/37574548/how-to-use-searchbar-for-apis). seems promising but new to me! – Twaha Mukammel Aug 18 '17 at 16:56
  • Seems good idea for now @FebinFathah – Twaha Mukammel Aug 18 '17 at 16:56

1 Answers1

0

In case you want search to work with API call, you can follow the concept of reloading data after every few characters are typed (example : every 3 characters typed) in textDidChange method of UISearchBar.

Alternatively data can be reloaded when user stops typing. Refer to link in order to follow this approach.

By reloading, I mean the method which will actually perform the stuff you want to do after the user stops typing.

Hooda
  • 1,157
  • 1
  • 9
  • 16