There are 2 unanswered posts already on this topic here and here, where no one provided a working solution to this problem.
First image shows iOS 10 behaviour of search controller, where you can see hierarchy on the left side and search controller frame on the right framed in red. View at the center in blue is the one displayed correctly in the table.
Second image shows iOS 11 behaviour where search controller exits the bounds of the tableView
header, and moves to the top of the screen which has no sense, because table view is positioned at 230 pixels from the top of the screen.
The code I used to display all of this is following (in viewDidLoad
):
self.definesPresentationContext = YES;
self.searchController = [[UISearchController alloc] initWithSearchResultsController:nil];
self.searchController.searchResultsUpdater = self;
self.searchController.dimsBackgroundDuringPresentation = NO;
self.searchController.searchBar.delegate = self;
self.searchController.searchBar.clipsToBounds = YES;
self.tableView.tableHeaderView = self.searchController.searchBar;
self.searchController.searchBar.placeholder = @"Enter name or email";
[self.searchController.searchBar sizeToFit];