I'd like to have a separate viewController as the searchResultsController however, I am getting unusual behaviour illustrated below.
I am setting up searchController as such;
func setUpSearchControllerAttributes() {
searchController = UISearchController(searchResultsController: searchResultsController)
searchController.delegate = searchResultsController
searchController.definesPresentationContext = true
searchController.hidesNavigationBarDuringPresentation = false
searchController.dimsBackgroundDuringPresentation = false
searchController.searchBar.sizeToFit()
searchController.searchBar.backgroundColor = .white
searchController.searchBar.barTintColor = .white
searchController.searchBar.placeholder = "Search"
searchController.searchBar.searchBarStyle = .minimal
}
When I add:
navigationItem.titleView = searchController.searchBar
I get:
I have set the searchResultsController view colour to .green with a low alpha for illustrative purposes.
As you can see the searchResultsController is overlapping the navigationBar.
Now when I set:
navigationItem.searchController = searchController
I get the desired result below:
Is there any explaination for this. Obviously the problem lies with setting the searchResultsController SearchBar as the navigationItem TextView.
I had;
searchController.definesPresentationContext = true
Which needed to be replaced by;
self.definesPresentationContext = true