Search code examples
iosios6uisearchbar

Hide UISearchBar until user scrolls?


I implemented a search bar and search display controller on top of my table view.

When the view loads the search bar and relative scopes are always visible.

Is there a simple way to hide it until the user scrolls down, like it happens in the Music app?


Solution

  • You need to add search bar as a header of the table view and then set the contentoffset property of table view in viewDidLoad as,

    [self.tableView setContentOffset:CGPointMake(0,44) animated:YES];//or (0, 88) depends on the height of it
    

    For search display controller, you can try this as well,

    [self.searchDisplayController setActive:NO animated:YES];