我正在尝试使用搜索栏打印出一个字符串,但我写的代理函数不起作用,我真的不明白我哪里出错了。有人可以建议吗?
class LandingPage: UIViewController, UISearchBarDelegate{
func searchBarSearchButtonClicked(_ searchBar: UISearchBar) {
print("search bar button clicked! ")
}
答案 0 :(得分:0)
如果您在storyboard中添加了搜索栏,则必须按住Ctrl键并拖动到ViewController黄色按钮并选择搜索栏代理。如果您在代码中创建了搜索栏,那么您必须在viewcontroller.swift中指定它的委托
searchbar.delegate = self