我在iOS 6应用程序中有UISearchBar
,它的功能完美,但在iOS 7中取消按钮和清除按钮不起作用,我无法返回。这是我的应用程序中的一个大问题,我需要解决它。iOS 7搜索栏 - 取消按钮不起作用
我的代码是:
- (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);
}
}
感谢您提前。
Possbile重复:UISearchBar's Cancel and Clear Buttons Not Working in iOS 7
编辑:
- (void)searchBarCancelButtonClicked:(UISearchBar *)searchBar
{
self.searchDisplayController.searchBar.hidden = YES;
self.tempImageView.hidden = NO;
[searchBar resignFirstResponder];
}
SOLUTION:
有了这个功能,我解决了这个问题:
-(void)searchDisplayControllerDidBeginSearch:(UISearchDisplayController *)controller
{
controller.active = YES;
[self.view addSubview:controller.searchBar];
[self.view bringSubviewToFront:controller.searchBar];
}
希望它有帮助!
为什么'searchDisplayControllerDidBeginSearch:'如果'controller'没有激活,甚至会被调用? – user102008
当控制器开始搜索时调用它。 – amurcia
按下取消按钮时调用什么方法? – mafiOSo