UISearchController with SearchBar not able to select search results


Currently implementing a view which has a UITableView and a UISearchController. I have assigned the SearchBar to the HeaderView of the UITableView.

The UITableView is pre loaded with data; lets say for example a list of Countries. As you begin to enter text in the SearchBar, the UITableView filters according to your search words (as it should). However, the problem is selecting one of the results in the UITableView. I am unable to select the Country and it then take me to the next screen.

Any help would be much appreciated.


So far I understand you use a single UITableView to present all data and the filtered results. If that is the case you might have something messed up in the different data source and delegate methods trying to differentiate between both collections. SoI’d suggest you try looking into that.
However UISearchController is designed to present search results in a separate view controller. So you might want to create a separate class or just a new instance of an existing class suitable to represent the filtered data and handle interaction with it there.

I hope it helped!

Here is a great tutorial which helped me figure out the answer.