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!
After initializing the searchController
, try setting the following property of searchController
that will enable didSelectRowAtIndexPath
method of UITableViewDelegate
searchController.obscuresBackgroundDuringPresentation = false
Try dismissing the Search Bar when the user selects the filtered table row:
[yourSearchController.searchBar resignFirstResponder];
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With