I created a UISearchController in a table view controller. I move on to this tabular view controller using the push segment from another view controller. I want the keyboard to appear with the cursor in the search bar as soon as the table view controller is pressed.
I made the search controller active in the viewDidLoad method using
self.mySearchController.active = true
It makes an active search controller, but it does not call the keyboard and does not place the cursor in the search bar. I also tried
self.mySearchController.searchBar.becomeFirstResponder()
This line does not seem to have any effect.
How can I open the keyboard automatically / programmatically? Below is a more detailed version of my code.
class PickAddressViewController: UITableViewController, UISearchResultsUpdating { var searchText = "" var mySearchController = UISearchController() override func viewDidLoad() { super.viewDidLoad() self.mySearchController = ({ let controller = UISearchController(searchResultsController: nil) controller.searchResultsUpdater = self controller.dimsBackgroundDuringPresentation = false controller.searchBar.sizeToFit() controller.searchBar.text = self.searchText self.tableView.tableHeaderView = controller.searchBar return controller })() self.mySearchController.active = true self.mySearchController.searchBar.becomeFirstResponder() }
ios swift uisearchcontroller
Roookiepro
source share