gpt4 book ai didi

ios - 在搜索按钮上隐藏键盘单击代码创建的搜索栏

转载 作者:可可西里 更新时间:2023-11-01 03:36:32 24 4
gpt4 key购买 nike

我使用下面的代码创建了一个搜索栏:

 UISearchBar *Search = [[UISearchBar alloc]initWithFrame:CGRectMake(150, 0,170 , 50)];
[SearchView addSubview:Search];

但是当我点击搜索按钮时,键盘并没有被隐藏。我使用了很多方法,例如 searchBarTextDidEndEditingsearchBarSearchButtonClicked。也许原因是我的搜索栏没有附加。我还在我的 .h 类和 .m unload 方法中使用了 UISearchBarDelegate 委托(delegate):

Search.delegate = Self;

任何人都可以建议我如何将由代码创建的搜索栏附加到我的 View Controller 以便它正常工作吗?

最佳答案

首先你需要设置你的 searchBar 的 delegate 然后你应该使用 UISearchBardelegate 方法,例如,

- (void)searchBarSearchButtonClicked:(UISearchBar *)searchBar
{
[searchBar resignFirstResponder];

}

关于ios - 在搜索按钮上隐藏键盘单击代码创建的搜索栏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20990938/

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