我已使用嵌入式导航栏设置了搜索栏。未检测到func searchBarSearchButtonClicked。我想这样做,以便当用户点击搜索栏时,将调用另一个函数。我已经拿出了一些与这个问题无关的无关代码。可能是什么问题?
class FirstViewController: UIViewController, UISearchBarDelegate {
var resultSearchController: UISearchController? = nil
override func viewDidLoad() {
super.viewDidLoad()
// set up the search results table
let locationSearchTable = storyboard!.instantiateViewController(withIdentifier: "LocationSearchTable") as! LocationSearchTable
resultSearchController = UISearchController(searchResultsController: locationSearchTable)
resultSearchController?.searchResultsUpdater = locationSearchTable
let searchBar = resultSearchController!.searchBar
searchBar.sizeToFit()
searchBar.placeholder = "Where would you like to go"
navigationItem.titleView = resultSearchController?.searchBar
searchBar.delegate = self
resultSearchController?.hidesNavigationBarDuringPresentation = false
resultSearchController?.dimsBackgroundDuringPresentation = true
definesPresentationContext = true
}
func searchBarSearchButtonClicked(_: UISearchBar) {
// closeMapType()
// self.mapType.transform = .identity
print("it worked")
}
}
答案 0 :(得分:0)
当用户点击搜索栏时,将调用以下函数:
func searchBarShouldBeginEditing(_ searchBar: UISearchBar) -> Bool {
return true
}
当我们点击"搜索"键盘上的按钮
func searchBarSearchButtonClicked(_: UISearchBar)