UISearchControllerDelegate - the search string does not appear in the table header

My UITableViewController matches the new UISearchControllerDelegate as well as UISearchResultsUpdating .

Here is my setup code for the search bar:

 override func viewDidLoad() { var searchController = UISearchController(searchResultsController: self) searchController.searchResultsUpdater = self self.tableView.tableHeaderView = searchController.searchBar self.definesPresentationContext = true } 

However, when launched in the simulator, the table heading does not have a search line, even if it is specified in the code. I also tried this code in viewWillAppear , but the search bar did not display again.

+6
source share
1 answer

I was informed by an Apple engineer that you should provide a search bar frame. If you print the frame of the search bar, you will notice that the height is zero. So this is probably an error in Apple code.

 searchController.searchBar = CGRectMake(0.0, 0.0, 320.0, 44.0) 

Edit:

The documentation states what you should pass to the view controller, which should display the results. To display this in the same view controller you are in, go to zero.

 var searchController = UISearchController(searchResultsController: nil) 
+9
source

Source: https://habr.com/ru/post/970567/


All Articles