gpt4 book ai didi

ios - UISearchcontroller 搜索栏委托(delegate)不工作

转载 作者:行者123 更新时间:2023-11-29 10:20:37 25 4
gpt4 key购买 nike

class PlaceSelectorViewController: UIViewController, GMSAutocompleteResultsViewControllerDelegate, UISearchBarDelegate {

我已经包含了搜索栏委托(delegate)

searchController?.searchBar.delegate = self

并且我已经设置了委托(delegate)。

但是方法

func searchBarCancelButtonClicked(_ searchBar: UISearchBar) {
stopHighlight()
}

不会发生。

Delegate 已正确设置并且 stopHighlight() 是一个真正的函数

最佳答案

viewdidload 方法中生成 searchbar 的委托(delegate)。

 override func viewDidLoad() {
super.viewDidLoad()
searchBarCustom.delegate = self
}

或者你可以在 Storyboard中将它设置为 enter image description here

-因此委托(delegate)将调用

 func searchBarCancelButtonClicked(_ searchBar: UISearchBar) {
print("searchBarCancelButtonClicked")
}

编辑:对于 UISearchController

var searchController: UISearchController!
func configureSearchController() {
// Initialize and perform a minimum configuration to the search controller.
searchController = UISearchController(searchResultsController: nil)
searchController.searchResultsUpdater = self
searchController.dimsBackgroundDuringPresentation = false
searchController.searchBar.placeholder = "Search here..."
searchController.searchBar.delegate = self
searchController.searchBar.sizeToFit()

// Place the search bar view to the tableview headerview.
tblSearchResults.tableHeaderView = searchController.searchBar
}

关于ios - UISearchcontroller 搜索栏委托(delegate)不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43706731/

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