Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 378
kain Avatar asked Dec 24 '12 05:12

kain


2 Answers

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];
like image 102
iDev Avatar answered Nov 21 '22 00:11

iDev


another approach without hardcode

[self.tableView setContentOffset:CGPointMake(0.0, self.tableView.tableHeaderView.frame.size.height) animated:YES];
like image 31
codercat Avatar answered Nov 21 '22 00:11

codercat