我已經使用嵌入導航欄設置了搜索欄。 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