gpt4 book ai didi

ios - 无法在 UISearchBar 中单击搜索按钮时隐藏键盘

转载 作者:可可西里 更新时间:2023-11-01 05:41:35 26 4
gpt4 key购买 nike

我正在使用 UISearchBar 来搜索列表,但是当我点击搜索按钮时在键盘上,键盘不隐藏。
请帮我解决这个问题。
这是我的代码

-(void)search:(UISearchBar*)searchbar Text:(NSString*)text
{
[copyListOfItems removeAllObjects];
if([text length] > 0) {
// [ovController.view removeFromSuperview];
searching = YES;
NSString *searchText = searchBar.text;
for(imergencyData *objtrust in aryTrustee)
{
NSRange titleResultsRange = [objtrust.strName rangeOfString:searchText options:NSCaseInsensitiveSearch];

if (titleResultsRange.length > 0)
[copyListOfItems addObject:objtrust];
}
NSLog(@"number of object found %d",copyListOfItems.count);
}
else
{
// [tblTrustee insertSubview:ovController.view aboveSubview:self.parentViewController.view];
[searchbar resignFirstResponder];
searching = NO;
//tblTrustee.scrollEnabled = NO;
}
[tblTrustee reloadData];
}

-(void)searchBarTextDidEndEditing:(UISearchBar *)aSearchBar
{
[aSearchBar resignFirstResponder];
[self.view endEditing:YES];
}

//Method call when type text in search box
-(void)searchBar:(UISearchBar *)theSearchBar textDidChange:(NSString *)searchText {
[self search:theSearchBar Text:searchText];

}
//method call when on search button
-(void)searchBarSearchButtonClicked:(UISearchBar *)searchBa{
[searchBa endEditing:YES];
[searchBa resignFirstResponder];
[self search:searchBa Text:searchBar.text];

}

最佳答案

把这行代码放上去试试,

- (void)searchBarTextDidEndEditing:(UISearchBar *)aSearchBar {
[aSearchBar resignFirstResponder];
[self.view endEditing:YES];
}

(或)编辑:

- (void)searchBarSearchButtonClicked:(UISearchBar *)searchBar{
[searchBar resignFirstResponder];
[self.view endEditing:YES];
}

关于ios - 无法在 UISearchBar 中单击搜索按钮时隐藏键盘,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16338196/

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