How to add a Search Display Controller to a UITableView (in code)

There is a new version of this article available as a screencast for iOS 7:

We’ve recently discussed how to deal with a Search Bar and Search Display Controller using Interface Builder. You can however do this in code too. This can be useful if you don’t want to make all the relevant connections in every Storyboard.

This example assumes you have a Table View (self.tableView) to which you’d like to add a Search Bar and Search Display Controller at the top. We do this by utilising the Table View’s tableHeaderView property:

Your View Controller also needs to conform to the UISearchBarDelegate Protocol for this to work properly.

About Jay Versluis

Jay is a medical miracle known as Super Survivor. He runs two YouTube channels, five websites and several podcast feeds. To see what else he's up to, and to support him on his mission to make the world a better place, check out his Patreon Campaign.

1 thought on “How to add a Search Display Controller to a UITableView (in code)

Leave a Reply to Jay Cancel reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.