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 ?
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
try this
@IBOutlet weak var searchBar: UISearchBar!
override func viewDidLoad()
{
super.viewDidLoad()
searchBar.becomeFirstResponder()
}
回答2:
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()
}
}