So you’re working on a search screen or popover with UITableViewController and you’re wondering how to get that fancy search magnifying glass in your search results, right?

Search

In my example, I have my table view sourced by a simple array of data. This may not be the case for you, but you get the idea from the example. Simply add the constant UITableViewIndexSearch as the first section header title – UITableView will understand to replace the {search} text from that constant with the locale-specific image indicating search.

[gist 3226609]

Then, you want to show the search bar when that icon is selected. Normal behavior when selecting an index in the right hand gutter is to scroll to that section header. The search magnifying glass, however, signifies the search bar section. The key is that you have to use a UISearchDisplayController and tell the table view to scroll up to the search bar’s rectangle:

[gist 3226628]

Pretty simple! This feature isn’t well documented in the Apple API but it’s quite handy for making your app feel native.