UISearchbar keyboard search button Action

懵懂的女人 提交于 2019-12-03 04:14:20
Milo

Add UISearchBarDelegate in .h

Also set SearchBar's object delegate to self.

Add this to the UISearchBarDelegate's method:

- (void)searchBarSearchButtonClicked:(UISearchBar *)searchBar
{
    [searchBar resignFirstResponder];
    // Do the search...
}

Swift

func searchBarSearchButtonClicked(_ searchBar: UISearchBar) {
    searchBar.resignFirstResponder()
}

In Swift 3:

 func searchBarSearchButtonClicked(_ searchBar: UISearchBar) {
        searchBar.resignFirstResponder()
 }

The textFieldShouldReturn method is a textField delegate method and not the one you're looking for. What you need is a UISearchBarDelegate method called searchButtonClicked, have a look here.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!