UISearchbar键盘搜索按钮动作 [英] UISearchbar keyboard search button Action
本文介绍了UISearchbar键盘搜索按钮动作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
当我在键盘显示的 UISearchBar
上输入文字时,我正在使用 UISearchBar
。那时,键盘返回键是搜索。
我想按键盘搜索按钮时实现事件。
如何实施该操作?
On UITextField
它有
I'm using UISearchBar
when I input text on UISearchBar
the keyboard shows. At that time, keyboard return key is "Search".
I want to implement event when I press the keyboard search button.
How can I implement the action?
On UITextField
it has
-(BOOL)textFieldShouldReturn:(UITextField *)textField;
但是在 UISearchBar
它没有返回行动。
But on UISearchBar
it doesn't have return action.
感谢您的帮助。
推荐答案
在.h中添加UISearchBarDelegate
还将SearchBar的对象委托设置为self。
将此添加到UISearchBarDelegate的方法:
Add this to the UISearchBarDelegate's method:
- (void)searchBarSearchButtonClicked:(UISearchBar *)searchBar
{
[searchBar resignFirstResponder];
// Do the search...
}
Swift
func searchBarSearchButtonClicked(_ searchBar: UISearchBar) {
searchBar.resignFirstResponder()
}
这篇关于UISearchbar键盘搜索按钮动作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文