Show keyboard automatically when UISearchController is loaded

后端 未结 6 1285
走了就别回头了
走了就别回头了 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:17

    I also tried the suggestions listed in the link mentioned by Nikita Leonov. I needed to add make the class a UISearchControllerDelegate & UISearchBarDelegate and then it worked. I don't u

    class PickAddressViewController: UITableViewController, UISearchControllerDelegate, UISearchBarDelegate, UISearchResultsUpdating {
    
        override func viewDidLoad() {
            super.viewDidLoad()
    
            self.mySearchController = ({
                controller.searchBar.delegate = self
            })()
    
            self.mySearchController.active = true
            self.mySearchController.delegate = self
        }
    
        func didPresentSearchController(searchController: UISearchController) {
            self.mySearchController.searchBar.becomeFirstResponder()
        }
        …
    }
    

提交回复
热议问题