Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/18.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/fortran/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios UISearchcontroller取消按钮不工作_Ios_Swift_Uisearchcontroller_Uisearchbardelegate - Fatal编程技术网

Ios UISearchcontroller取消按钮不工作

Ios UISearchcontroller取消按钮不工作,ios,swift,uisearchcontroller,uisearchbardelegate,Ios,Swift,Uisearchcontroller,Uisearchbardelegate,我在班上有一门外语 class PlaceSelectorViewController: UIViewController, GMSAutocompleteResultsViewControllerDelegate, UISearchBarDelegate, UISearchControllerDelegate { 我已经将代理设置为Self searchController?.searchBar.delegate = self 但是此委托调用不起作用您的UI搜索栏需要一个outleet(假

我在班上有一门外语

class PlaceSelectorViewController: UIViewController, GMSAutocompleteResultsViewControllerDelegate, UISearchBarDelegate, UISearchControllerDelegate {
我已经将代理设置为Self

searchController?.searchBar.delegate = self

但是此委托调用不起作用

您的UI搜索栏需要一个
outleet
(假设您使用的是情节提要,这非常简单,只需通过助理编辑器拖放即可)。这就是您要添加代理的内容。在以编程方式构建的情况下,该变量将被分配给委托

下面是构建故事板的示例代码

@ibvar搜索栏:UISearchBar(你必须在右边看到一个填充的圆圈,否则故事板和这个插座之间没有链接)

override func viewDidLoad(){
super.viewDidLoad()
searchBar.delegate=self

}

您何时调用此:searchController?.searchBar.delegate=self?您的searchController是否已存在?您是否在viewDidLoad()中设置委托?没有其他名为searchController的变量,并且委托已在viewDidLoad()上设置
func searchBarCancelButtonClicked(_ searchBar: UISearchBar) {
    stopHighlight()
}