我已经使用嵌入导航栏设置了搜索栏。 func searchBarSearchButtonClicked未被检测到。我想这样做是为了当用户点击搜索栏时,会调用另一个函数。我已经拿出了一些与这个问题无关的无关代码。可能是什么问题?当用户点击搜索栏上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")
}
}
代码似乎点击“搜索”按钮你在设备上尝试过很好吗?并按下输入,如果在模拟器的情况下 –
是的,它没有工作,打印功能没有显示 – zachenn