UISearchBar and UISearchDisplayController with Custom Cells Programmatically

This post is not a full tutorial of how to implement this. It is just my experience description. Probably, you have the same problem with custom cells, as I had. There are a lot of tutorials, search them in Google. Another nice tutorial.

I had highly customized cells, but couldn’t understand, why do they mess up, when search starts and self.searchDisplayController.searchResultsTableView is displayed with regular cell, but not customized cells. I tried to find solution for about 2-3 hours, then I decided to make exactly the same, as others did for using custom cells. I solved the problem, that was in the absence of two delegate properties in my code. This is the correct version, of how you should initialize your UISearchBar and UISearchDisplayController (if you are doing it programmatically).

Code for ViewDidLoad method:

The other parts are pretty analogous to the usual search bar usage with regular cells. For instance, look at Apple’s source code on this topic.

What is interesting, this works fine on iPad too even thought the frame is 320 px here.

UISearchBar Class reference

UISearchDisplayController Class Reference

Leave a Reply

Your email address will not be published. Required fields are marked *