UISeachBar detect when user press Search button

≯℡__Kan透↙ 提交于 2019-12-04 15:21:04

问题


I try to get notification when the Search button is clicked in the keyboard in the UISearchBar with this :

    - (BOOL)textFieldShouldReturn:(UITextField *)textField{

        return YES;
    }

But this method won't call when I press the Search button.


回答1:


Have you tried this delegate

Objective-C:

- (void)searchBarSearchButtonClicked:(UISearchBar *)searchBar

Swift:

func searchBarSearchButtonClicked(searchBar: UISearchBar)

See the documentation for any searchbar delegates. https://developer.apple.com/documentation/uikit/uisearchbardelegate




回答2:


If you want to do something upon 'search' button get clicked then, Try this method

  • (void)searchBarSearchButtonClicked:(UISearchBar *)searchBar

Tells the delegate that the search button was tapped.




回答3:


You've to set the searchBar delegate first. In the viewDidLoad()

self.searchBar.delegate = self

then func searchBarSearchButtonClicked(searchBar: UISearchBar)



来源:https://stackoverflow.com/questions/9905013/uiseachbar-detect-when-user-press-search-button

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