Swift: Search bar created at Auto Focus

前端 未结 3 1623
灰色年华
灰色年华 2021-01-14 11:34

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 t

3条回答
  •  花落未央
    2021-01-14 11:58

    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()
       }
    }
    

提交回复
热议问题