gpt4 book ai didi

ios - 如何在出现 searchController 时自动显示键盘

转载 作者:行者123 更新时间:2023-11-28 10:54:09 26 4
gpt4 key购买 nike

@IBAction func MapSearchController(_ sender: UIBarButtonItem) {

let searchTable = storyboard!.instantiateViewController(withIdentifier: "SearchTableViewController") as! SearchTableViewController

mapSearchController = UISearchController(searchResultsController: searchTable)
mapSearchController.searchResultsUpdater = searchTable
present(mapSearchController!, animated: true, completion: nil)
mapSearchController.searchBar.becomeFirstResponder()
self.mapSearchController.dimsBackgroundDuringPresentation = true
self.mapSearchController.searchBar.sizeToFit()
self.mapSearchController.searchBar.barTintColor = UIColor.black
self.mapSearchController.searchBar.placeholder = "חפש ברים"
self.mapSearchController.hidesNavigationBarDuringPresentation = true
mapSearchController.searchBar.delegate = self
definesPresentationContext = true
searchTable.mapView = mapView
searchTable.handleMapSearchDelegate = self

如何在出现 searchController 时自动显示键盘?我尝试了很多解决方案,但没有一个对我有用......包括 becomeFirstResponder() 等等......请帮忙

最佳答案

问题是加载 View ID 时不显示搜索 Controller ,因此即使在 make becomeFirstResponder 之后也不能解决问题。下面的代码将解决这个问题,并在搜索栏中使用光标打开键盘。

override func viewDidAppear(_ animated: Bool) {
DispatchQueue.main.async {
self.searchController.searchBar.becomeFirstResponder()
}
}

关于ios - 如何在出现 searchController 时自动显示键盘,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44595188/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com