I want to add a search on top of a UITableViewController, but I want the field to be hidden initially (like Notes app) until the user pulls down to reveal it. How can I achieve this?
Thank you,
I want to add a search on top of a UITableViewController, but I want the field to be hidden initially (like Notes app) until the user pulls down to reveal it. How can I achieve this?
Thank you,
You can use a tableview searchbar with the searchbar delegate.
On the viewDidLoad method you can manually scroll up the tableview. You can set an IBOulet on the searchbar to access its frame's height to know its height.
You should use UITableView
's tableHeaderView
. When done in code, it looks like this:
-(void)viewDidLoad
{
[super viewDidLoad];
UISearchBar *searchBar = [[UISearchBar alloc]initWithFrame:CGRectMake(self.tableView.bounds.origin.x, self.tableView.bounds.origin.y, self.tableView.bounds.size.width, 44.0)];
self.mySearchDisplayController = [[UISearchDisplayController alloc] initWithSearchBar:searchBar contentsController:self];
self.mySearchDisplayController.searchResultsDelegate = self;
self.mySearchDisplayController.searchResultsDataSource = self;
self.mySearchDisplayController.delegate = self;
self.tableView.tableHeaderView = searchBar;
}