UISearchController search bar overlap first cell when active

uisearchcontroller delegate
uisearchcontroller programmatically objective-c
uisearchcontroller vs uisearchbar
uisearchcontroller objective-c
uisearchdisplaycontroller to uisearchcontroller

I am using UISearchController to search for data in my tableview. I am not using table view controller. I would like to hide the navigation bar when my search bar is active therefore I set self.searchController.hidesNavigationBarDuringPresentation = YES; to yes.

However when I do this and want to search, my active search bar covers part of the first cell. the covered part has same height as status bar.

I tried other articles and questions similar to this one but nothing helped me to solve it. Then I started to play with the table view header size. I did this

 -(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{

  return 20.0f;
}

The result was that when I tapped search bar an started to search problem was not there anymore.

However when the search bar is not active there was a gab between searchbar and first cell

Any ideas how to fix this issue?

Edit: after adding self.automaticallyAdjustsScrollViewInsets = false;

This is how I set up the search bar and things in viewDidLoad (copied from some of apple's examples).

It presents the found results in the same view controller as your unfiltered data is shown. It also has its search bar in the table header that is hidden until it is needed.

self.searchController = [[UISearchController alloc] initWithSearchResultsController:nil];
self.searchController.searchResultsUpdater = self;
self.tableView.tableHeaderView = self.searchController.searchBar;
[self.searchController.searchBar sizeToFit];

// we want to be the delegate for our filtered table so didSelectRowAtIndexPath is called for both tables
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, the 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

// Hides search bar initially. When the user pulls down on the list, the search bar is revealed.
[self.tableView setContentOffset:CGPointMake(0, self.searchController.searchBar.frame.size.height)];

UISearchController's search bar overlaps first tableview cell, Having the Search Display Controller and SearchBar in the searchController. active) { return 44; // with scope } else { return 0; // no scope } }. The search bar is added as a subview to a UIView which is above the UItableView. I have done it this way since I want the search bar to be always visible even when the tableview is scrolled. The problem is the scopebar overlaps the first tableview cell. StoryBoard. Scope bar overlapping the tableview cell

I managed to resolve this issue by combining RJiryes answer with scroll to top.

-(void)willPresentSearchController:(UISearchController *)searchController{

     [self.contactsTableView setContentInset:UIEdgeInsetsMake(20, 0, 0, 0)];
     [self.contactsTableView setContentOffset:CGPointMake(0.0f, -self.contactsTableView.contentInset.top) animated:YES];
 }

-(void)willDismissSearchController:(UISearchController *)searchController{

     [self.contactsTableView setContentInset:UIEdgeInsetsMake(0, 0, 0, 0)];
}

UISearchController search bar overlap first cell when active, I am using UISearchController to search for data in my tableview. I am not using table view controller. I would like to hide the navigation bar when my search bar� The search bar is placed inside the header view of the table view. The table view content is offset with the same height as the search bar so that the search bar is hidden at first. Upon scrolling up past the top edge of the table view, the search bar is revealed. Then when the search bar becomes active, it hides the navigation bar.

You can add content inset from the top instead of adding a header.

  self.tableView.contentInset = UIEdgeInsets(top: 20, left: 0, bottom: 0, right: 0)

and when willDismissSearchController (UISearchController's delegate method) is called, return the insets to 0

  self.tableView.contentInset = UIEdgeInsets(top: 0, left: 0, bottom: 0, right: 0)

This way, you'll avoid the whitespace when it's not active.

UISearchBar overlaps with UITableView content when active, UISearchController search bar overlap first cell when active, iOS 7 UISearchDisplayController search bar overlaps status bar while searching � Ask Question. To ensure the correct configuration of your search bar, lazily initialize it when it’s first requested, as shown in the code below. class CustomSearchController: UISearchController { // Mark this property as lazy to defer initialization until // the searchBar property is called.

Not the best solution but just to workaround.

-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section { return searchController.isActive ? 20.0f : 0.0f; }

UISearchController search bar overlap first cell w, However when I do this and want to search, my active search bar covers part of the first cell. the covered part has same height as status bar. To control when search results display, you need to react to changes in the search bar. For this to work, the main view controller will conform to UISearchResultsUpdating. The delegate receives a call to updateSearchResults (for:) when the search bar becomes the first responder or when text changes.

I have seen similar behavior. Most probably, your table view controller is not implementing heightForHeaderInSection. Precise height of cell is not known, this leads to number of issues like yours.

UISearchBar with tableHeaderView l…, UISearchBar with tableHeaderView layout problem under iOS 13 The scope buttons appear when the search bar becomes the first responder and they as before, but located so that the scope buttons now overlay the top item in the tableview. At one point I had the new method working if activated the search bar twice. You adopt this protocol from the view controller class to save the search bar’s active state, first responder status, and search bar text and restore them when the app is relaunched. Create a Search Controller. Use Main Table View Controller, a subclass of UITable View Controller, to create a search controller.

Search bar overlapping status bar in search controller, I created a UISearchController programmatically in a UITableViewController. When there are few cells on the tableview, the search bar drops down as in this When the search bar becomes active, a new navigation controller (N2) is bar which is displayed without a search bar on it when the screen first displayed. Home · iOS & Swift Tutorials UISearchController Tutorial: Getting Started. In this tutorial, you’ll build a searchable Candy app based on a standard table view. You’ll add table view search capability, dynamic filtering and an optional scope bar using UISearchController, UISearchBar and friends.

UITableView overlaps the status bar - any help? : swift, This seems to be a common problem and a search turns up many people looking for the Today I solved the first challenge in my life (programming) by myself. I'm in the process of refactoring UISearchDisplayController with UISearchController and I've run into a snag. I'm using a separate ResultsViewController with the SearchController in order to allow the "dimmed" view when search is active but no text has been entered and the "active" results view that shows results once a user has started typing.

ios, 我正在使用UISearchController在表UISearchController中搜索数据。 我没有使用 UISearchController search bar overlap first cell when active. iOS UI Search Bar. In iOS search bar is used to search items in the collection. Basically the search bar in iOS will provide textbox with search and cancel buttons interface and it will allow users to search for required data from collection items based on the text entered in a textbox.

Comments
  • Try adding self.automaticallyAdjustsScrollViewInsets = false in viewDidLoad
  • it hid the status bar from the top but the first cell is still covered.
  • That's weird, it shouldn't affect the visibility of the status bar.
  • requirement: navigationItem.searchController = searchController, do not solve the problem for me.
  • That is because (I think) your search bar is always visible. Some implementations suggest to keep it hidden until its needed. You might like to do this when setting it up in viewdidload. Will move to separate post below.
  • Worked for me, without the setContentOffset part.
  • This did not helped me
  • @beowulf how did you implement it?
  • i did put the content inset inside willPresentSearchController and removed that in willDismissSearchController
  • And? Did it not push the content of the tableView down? What was the problem exactly? Otherwise it will be hard for anyone to "help" without giving more details. :-)
  • It did not push it down. Looks same as on the first image. I was able to see the contentInset only after manually scrolling the table view.
  • I have both methods for height of header view and also for the cell implemented.