I am creating a table view and a search bar by clicking on a button.But I need the search bar to appear at Auto Focus ( where the user enters text immediately with no need to click inside the search bar). How can I do that ?
try this
@IBOutlet weak var searchBar: UISearchBar!
override func viewDidLoad()
{
super.viewDidLoad()
searchBar.becomeFirstResponder()
}
This should do it.
override func viewWillAppear(animated: Bool) {
super.viewWillAppear(animated)
searchController.active = true
}
...
extension GDSearchTableViewController: UISearchControllerDelegate {
func didPresentSearchController(searchController: UISearchController) {
searchController.searchBar.becomeFirstResponder()
}
}
来源:https://stackoverflow.com/questions/31786050/swift-search-bar-created-at-auto-focus