UISearchDisplayController的searchResultsTableView的ContentSize不正确。 在iOS 7中的错误?

下面的问题只发生在iOS 7.0以上版本的iOS 6.0 / 6.1应用程序上。

所以我有一个UISearchDisplayController ,它search我们的API并返回数据。 这一切正常,一切都按照我们的要求显示。 我们看到的唯一的问题是,在内容填充了searchResultsTableView ,似乎好像键盘最初隐藏时, searchResultsTableViewcontentSize比数据大得多,而实际上似乎是键盘的大小。 当我进入search栏,并显示键盘,再次点击“search”(只是隐藏键盘), contentSize然后正确调整,只填满屏幕,没有更多。 下面是我正在讨论的最初的tableView人口的屏幕截图。

白色是表格数据,灰色/奶油色是额外的tableView空间。

有想法该怎么解决这个吗?

我有这个确切的问题。 在这里的开发人员论坛上发布的解决scheme为我工作。 不知道这是在iOS 7中的错误,或者只是他们改变了他们的做法,但这是我发现解决我的问题的唯一解决scheme。

解决scheme从懒惰的论坛post:

 - (void)searchDisplayController:(UISearchDisplayController *)controller didHideSearchResultsTableView:(UITableView *)tableView { [[NSNotificationCenter defaultCenter] removeObserver:self name:UIKeyboardWillHideNotification object:nil]; } - (void)searchDisplayController:(UISearchDisplayController *)controller willShowSearchResultsTableView:(UITableView *)tableView { [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillHide) name:UIKeyboardWillHideNotification object:nil]; } - (void) keyboardWillHide { UITableView *tableView = [[self searchDisplayController] searchResultsTableView]; [tableView setContentInset:UIEdgeInsetsZero]; [tableView setScrollIndicatorInsets:UIEdgeInsetsZero]; } 

这个系统错误仍然在iOS 8中,接受答案的解决scheme不再工作。 所以,你应该使用下面的解决scheme:

 -(void)searchDisplayController:(UISearchDisplayController *)controller didHideSearchResultsTableView:(UITableView *)tableView { [[NSNotificationCenter defaultCenter] removeObserver:self name:UIKeyboardWillHideNotification object:nil]; } -(void)searchDisplayController:(UISearchDisplayController *)controller willShowSearchResultsTableView:(UITableView *)tableView { [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillHide:) name:UIKeyboardWillHideNotification object:nil]; } -(void)keyboardWillHide:(NSNotification*)notification { CGFloat height = [[[notification userInfo] objectForKey:UIKeyboardFrameEndUserInfoKey] CGRectValue].size.height; UITableView *tableView = [[self searchDisplayController] searchResultsTableView]; UIEdgeInsets inset; [[[UIDevice currentDevice] systemVersion] floatValue] >= 8.0 ? (inset = UIEdgeInsetsMake(0, 0, height, 0)) : (inset = UIEdgeInsetsZero); [tableView setContentInset:inset]; [tableView setScrollIndicatorInsets:inset]; }