简体   繁体   中英

UISearchController Hide Search Bar

I have a UISearchController in my UITableViewController. I'd like the search bar to be hidden until the user scrolls down. In the old UISearchDisplayController, I had the following code in my viewDidLoad method:

//Hides the search bar until user manually scrolls up.
[self.tableView scrollToRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0] atScrollPosition:UITableViewScrollPositionTop animated:NO];
CGRect newBounds = self.tableView.bounds;
newBounds.origin.y = newBounds.origin.y + self.searchBar.bounds.size.height;
self.tableView.bounds = newBounds;

Unfortunately, the above code no longer works with the UISearchController.

Just figured out the problem. The below is wrong,

newBounds.origin.y = newBounds.origin.y + self.searchBar.bounds.size.height;

it should be

newBounds.origin.y = newBounds.origin.y + self.searchController.searchBar.bounds.size.height;

Instead of self.searchBar, it needs to be self.searchController.searchBar

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM