I have a problem with the search bar. I need to create a table view with a search button in the right corner, and when I click on it, it should display a search bar.
My code is here:
searchController = ({
let controller = UISearchController(searchResultsController: nil)
controller.delegate = self
controller.searchBar.delegate = self
controller.searchResultsUpdater = self
controller.dimsBackgroundDuringPresentation = false
controller.hidesNavigationBarDuringPresentation = true
controller.searchBar.sizeToFit()
return controller
})()
And here is the action:
@IBAction func search(sender: UIBarButtonItem) {
print("Open search")
searchController.active = true
if searchController.searchBar.isFirstResponder() == false {
searchController.searchBar.becomeFirstResponder()
}
}
When I click on the button, nothing happens (it only prints text on the console), and what I want is in the image below:

source
share