[英]iOS 7 Search Bar - Cancel button doesn't work
I have a UISearchBar
in iOS 6 app and it works perfectly, but in iOS 7 the cancel button and the clear button don't work and I can't return back. 我在iOS 6应用程序中有一个
UISearchBar
,它运行良好,但在iOS 7中,取消按钮和清除按钮不起作用,我无法返回。 It's a big problem in my app and I need to solve it. 这是我的应用程序中的一个大问题,我需要解决它。
My code is: 我的代码是:
- (BOOL)searchDisplayController:(UISearchDisplayController *)controller shouldReloadTableForSearchString:(NSString *)searchString
{
// -- iOS 7 Hack
if (!SYSTEM_VERSION_LESS_THAN(@"7.0")) {
controller.searchResultsTableView.frame = CGRectMake(0, 64, self.view.frame.size.width, self.view.frame.size.height-64);
[controller.searchContentsController.view setNeedsLayout];
}
[self filterContentForSearchText:searchString scope:nil];
return YES;
}
- (void) searchDisplayController:(UISearchDisplayController *)controller didShowSearchResultsTableView:(UITableView *)tableView {
// iOS7 Hack
if (!SYSTEM_VERSION_LESS_THAN(@"7.0")) {
controller.searchResultsTableView.contentInset = UIEdgeInsetsMake(0.f, 0.f, 0.f, 0.f);
}
}
Thank you for advance. 谢谢你提前。
Possbile duplicate: UISearchBar's Cancel and Clear Buttons Not Working in iOS 7 Possbile重复: UISearchBar的取消和清除按钮在iOS 7中不起作用
EDIT: 编辑:
- (void)searchBarCancelButtonClicked:(UISearchBar *)searchBar
{
self.searchDisplayController.searchBar.hidden = YES;
self.tempImageView.hidden = NO;
[searchBar resignFirstResponder];
}
SOLUTION: 解:
With this function I resolved the problem: 有了这个功能,我解决了这个问题:
-(void)searchDisplayControllerDidBeginSearch:(UISearchDisplayController *)controller
{
controller.active = YES;
[self.view addSubview:controller.searchBar];
[self.view bringSubviewToFront:controller.searchBar];
}
Hope it helps! 希望能帮助到你!
IOS 7 default search bar will be transparent cancel button IOS 7默认搜索栏将是透明取消按钮
- (void)searchBarCancelButtonClicked:(UISearchBar *)aSearchBar
{
[aSearchBar resignFirstResponder];
isSearching = NO;
aSearchBar.text = @"";
[diaryTableView reloadData];
}
With this function I resolved the problem: 有了这个功能,我解决了这个问题:
-(void)searchDisplayControllerDidBeginSearch:(UISearchDisplayController *)controller
{
controller.active = YES;
[self.view addSubview:controller.searchBar];
[self.view bringSubviewToFront:controller.searchBar];
}
Hope it helps! 希望能帮助到你!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.