views:

119

answers:

2

Hi,

is there any easy way in the iPhone SDK to include search bars like those in the iPod app or in the Contacts app? (They behave and look unlike the usual UISearchBars ...)

-- Ry

A: 

This adds a search bar to a table view as the header view. This means that it scrolls with the table view:

- (void) viewDidLoad
{
    [super viewDidLoad];
    UISearchBar* searchBar = [[UISearchBar alloc] initWithFrame: CGRectMake(0, 0, 320, 45)];
    if (searchBar != nil) {
        // Your UISearchBar specifics here
        self.tableView.tableHeaderView = searchBar;
    }
}
St3fan
+2  A: 

Check out UISearchDisplayController. It handles the repositioning of the search bar, the graying of the screen, etc, etc, etc.

UIViewController has a UISearchDisplayController property, so it's pretty easy to hook up. There's also the TableSearch sample code.

Jablair
Cool! That's exactly what I was looking for, thanks!