Is there a way to use UISearchController
in a way that lets me storyboard the UISearchBar
? I have a storyboarded UI with a navigation bar which contains my search bar. It would be great if I could keep it this way because setting up the layout programmatically would be really inconvenient. I know the old UISearchDisplayController
could be storyboarded. Is there a way to do something similar with UISearchController?
Asked
Active
Viewed 4,193 times
1

A Tyshka
- 3,830
- 7
- 24
- 46
2 Answers
5
Add a UIView
to your layout. That will be the container for your UISearchBar
. Then programmatically instantiate the UISearchController and then add the searchbar to the container:
let searchController = UISearchController(searchResultsController: searchResultsController)
searchBarContainer.addSubview(searchController.searchBar)

mylovemhz
- 512
- 6
- 14
-
But atfter going through this, it leaves a UINavigationBar at the top of the parent view controller view. And I couldn't figure out any way to dismiss it. What shall we do? – Randika Vishman Aug 31 '20 at 18:33
0
No, unfortunately that is not possible yet (iOS 10 and before). See this example code which was updated for iOS 10 that shows how to setup the UISearchController programmatically.

Raphael
- 2,691
- 1
- 16
- 21