gpt4 book ai didi

iphone - UISearchbar 键盘搜索按钮操作

转载 作者:IT老高 更新时间:2023-10-28 11:48:38 27 4
gpt4 key购买 nike

当我在键盘显示的 UISearchBar 上输入文本时,我正在使用 UISearchBar。此时,键盘返回键为“搜索”。我想在按下键盘搜索按钮时实现事件。如何实现该操作?在 UITextField 上有

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

但是在 UISearchBar 上它没有返回 Action 。

感谢您的帮助。

最佳答案

在 .h 中添加 UISearchBarDelegate

还将 SearchBar 的对象委托(delegate)设置为 self。

将此添加到 UISearchBarDelegate 的方法中:

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

swift

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

关于iphone - UISearchbar 键盘搜索按钮操作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17628269/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com