iOS 7搜索栏 - 取消按钮不起作用

时间:2014-01-20 12:10:23

标签: ios objective-c ios7 uisearchbar

我在iOS 6应用程序中有一个UISearchBar并且它运行良好,但在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];
}

希望它有所帮助!

2 个答案:

答案 0 :(得分:0)

IOS 7默认搜索栏将是透明取消按钮

- (void)searchBarCancelButtonClicked:(UISearchBar *)aSearchBar
{
    [aSearchBar resignFirstResponder];
    isSearching = NO;
    aSearchBar.text = @"";

    [diaryTableView reloadData];

}

答案 1 :(得分:0)

使用此功能我解决了问题:

-(void)searchDisplayControllerDidBeginSearch:(UISearchDisplayController *)controller
{
    controller.active = YES;

    [self.view addSubview:controller.searchBar];
    [self.view bringSubviewToFront:controller.searchBar];
}

希望它有所帮助!

相关问题