How do I get UISearchController to work with the UISearchBar Interface Builder control?

How do I get a UISearchController to work with the search bar control in Interface Builder? I have tried the followin code:

@IBOutlet weak var searchBar: UISearchBar!  

searchController.searchBar = searchBar  

This gives me an error during coding time saying that searchController.searchBar is a get-only property.

@IBOutlet weak var searchBar: UISearchBar!  

searchBar = searchController.searchBar  

This gives me the UI I want, but the search doesn’t work.

var searchBar: UISearchBar!  

searchBar = searchController.searchBar  

NSLayoutConstraint(searchBar, ..... )  

This works, except that when I start typing in the search bar, the search bar disappears.

This topic was automatically closed after 166 days. New replies are no longer allowed.