Show keyboard automatically when UISearchController is loaded

后端 未结 6 1183
走了就别回头了
走了就别回头了 2021-02-05 23:39

I created a UISearchController in a table view controller. I segue to this table view controller using a push segue from another view controller. I want the keyboard to show up

6条回答
  •  后悔当初
    2021-02-06 00:12

    Swift 3 solution in my case:

    override func viewDidLoad() {
        super.viewDidLoad()
        navigationItem.titleView = mySearchController.searchBar
        mySearchController.searchResultsUpdater = self
        mySearchController.delegate = self
    
    }
    
    override func viewDidAppear(_ animated: Bool) {
        DispatchQueue.main.async {
            self.mySearchController.isActive = true
        }
    }
    
    func presentSearchController(_ searchController: UISearchController) {
        mySearchController.searchBar.becomeFirstResponder()
    }
    

提交回复
热议问题