Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UISearchController - how to select results from filtered table

I am working on adding a search bar in to an existing app.

I have a table that is populated with data downloaded from a server, and I am using the new UISearchController.

I have the search bar all fully working now, and displaying a new filtered table of results as the user types into the search bar.

My question is how to handle the user selecting an item from this new filtered table of search results?

I added a new segue from my filtered table and added a didSelectRowAtIndexPath, which does work fine - but when a user selects an item from the filtered table, the search bar remains, and clicking cancel after that point crashes the app.

So I am not sure what I am supposed to do and how I am supposed to handle a user selecting items from the filtered table?

Do I keep things the way I have them, but add some code to cancel the search bar when the user selects an item?

Or am I doing this wrong, and there is a way to hand the selection back from the filtered table back to the main viewcontroller table on user selection of a filtered item?

Any assistance, as always, very gratefully received!

like image 470
R2D2 Avatar asked Aug 24 '15 11:08

R2D2


2 Answers

After initializing the searchController, try setting the following property of searchController that will enable didSelectRowAtIndexPath method of UITableViewDelegate

searchController.obscuresBackgroundDuringPresentation = false
like image 189
Mohammed Shakeer Avatar answered Oct 13 '22 10:10

Mohammed Shakeer


Try dismissing the Search Bar when the user selects the filtered table row:

[yourSearchController.searchBar resignFirstResponder];
like image 31
Gjchoza Avatar answered Oct 13 '22 09:10

Gjchoza