UISearchBar overlaps with UITableView content when it is active

I have a view controller with a table view and a UISearchController. When I started the application, I found that the search bar overlaps the content when it is active. What do I need to configure so that the content does not overlap when the search bar is active?

Normal view:

enter image description here

Search bar is active:

enter image description here

View controller settings:

enter image description here

+8
source share
5 answers

The problem is that you have automaticallyAdjustsScrollViewInsets = true

uncheck enter image description here

will help:)

+3
source

You can use the " UISearchController " as follows:

 _searchController = [[UISearchController alloc] initWithSearchResultsController:self.resultsTableController]; self.searchController.searchResultsUpdater = self; [self.searchController.searchBar sizeToFit]; self.tableView.tableHeaderView = self.searchController.searchBar; // we want to be the delegate for our filtered table so didSelectRowAtIndexPath is called for both tables self.resultsTableController.tableView.delegate = self; self.searchController.delegate = self; self.searchController.dimsBackgroundDuringPresentation = NO; // default is YES self.searchController.searchBar.delegate = self; // so we can monitor text changes + others // Search is now just presenting a view controller. As such, normal view controller // presentation semantics apply. Namely that presentation will walk up the view controller // hierarchy until it finds the root view controller or one that defines a presentation context. // self.definesPresentationContext = YES; // know where you want UISearchController to be displayed 

You can use this working Apple Reference Code Example for more details.

+1
source

Try putting your SearchBar in the TableView header.

0
source

This is due to the display of the search bar when scrolling on iOS 11.

 if #available(iOS 11.0, *) { navigationItem.searchController = searchController navigationItem.hidesSearchBarWhenScrolling = false } else { // Fallback on earlier versions tableView?.tableHeaderView = searchController.searchBar } 
0
source

Write this in your viewDid ().

source: apple

 if #available(iOS 11.0, *) { // For iOS 11 and later, place the search bar in the navigation bar. navigationItem.searchController = searchController // Make the search bar always visible. navigationItem.hidesSearchBarWhenScrolling = false } else { // For iOS 10 and earlier, place the search controller search bar in the table view header. tableView.tableHeaderView = searchController.searchBar } 
0
source

All Articles