Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I make a UISearchController start hidden?

I have added a UISearchController to my code using the following method:

self.searchController = [[UISearchController alloc] initWithSearchResultsController:nil];
self.searchController.searchResultsUpdater = self;
self.searchController.dimsBackgroundDuringPresentation = NO;
self.searchController.searchBar.scopeButtonTitles = @[];
self.searchController.searchBar.delegate = self;

self.tableView.tableHeaderView = self.searchController.searchBar;
[self.searchController.searchBar sizeToFit];
self.definesPresentationContext = YES;

This creates my search controller and adds it to the top of my tableView. Annoyingly it starts visible though:

enter image description here

I can hide it by sliding it up under the navigation bar which suggests the underlying functionality of the code is working but I can't get it to start hidden so I can slide it down.

I have tried adjusting the edge insets, I have tried setting the navigation bar to translucent, I have tried to go through the search bar tutorials online but nothing seems to be dealing with this issue.

Any help very welcome

like image 484
sam_smith Avatar asked Feb 09 '23 22:02

sam_smith


1 Answers

Did you try setting the content offset of your table view?

[self.tableView setContentOffset:CGPointMake(0, self.searchController.searchBar.frame.size.height) animated:NO];
like image 132
aksh1t Avatar answered Feb 19 '23 10:02

aksh1t