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

Ale*_*ler 27 uisearchdisplaycontroller ios uisearchresultscontroller ios6 ios7

以下问题仅发生在iOS 7.0+设备上运行的iOS 6.0/6.1应用程序上.

所以我有一个UISearchDisplayController搜索我们的API并返回数据.这一切都有效,一切都按我们的意愿显示.我们所看到的唯一的问题是,内容填充后searchResultsTableView,却仿佛当键盘最初是隐藏的,在contentSizesearchResultsTableView比数据大得多,实际上似乎是键盘的尺寸.当我进入搜索栏,并显示键盘并再次点击"搜索"(只是为了隐藏键盘)时,contentSize然后正确调整以仅填充屏幕,仅此而已.下面是我与初始tableView人口谈论的屏幕截图.

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

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

Reb*_*ard 62

我有这个确切的问题.张贴在开发者论坛的解决方案在这里为我工作.不确定这是iOS 7中的错误,还是他们改变了他们做事的方式,但这是我发现解决问题的唯一解决方案.

来自论坛帖子的懒人解决方案:

- (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];

}
Run Code Online (Sandbox Code Playgroud)


All*_*len 8

此系统错误仍然存​​在于iOS 8中,并且接受答案的解决方案不再起作用.因此,您应该使用以下解决方案:

-(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];
}
Run Code Online (Sandbox Code Playgroud)