UISearchDisplayController';s searchResultsTableView';的内容大小不正确。iOS 7中的Bug?

UISearchDisplayController';s searchResultsTableView';的内容大小不正确。iOS 7中的Bug?,ios,ios6,ios7,uisearchdisplaycontroller,uisearchresultscontroller,Ios,Ios6,Ios7,Uisearchdisplaycontroller,Uisearchresultscontroller,以下问题仅在iOS 7.0+设备上运行的iOS 6.0/6.1应用程序上发生 因此,我有一个UISearchDisplayController,它搜索我们的API并返回数据。这一切都是可行的,一切都是我们想要的。我们看到的唯一问题是,在内容填充了searchResultsTableView之后,似乎当键盘最初被隐藏时,searchResultsTableView的contentSize比数据大得多,实际上似乎是键盘的大小。当我进入搜索栏,显示键盘并再次点击“搜索”(只是为了隐藏键盘)时,cont

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

因此,我有一个
UISearchDisplayController
,它搜索我们的API并返回数据。这一切都是可行的,一切都是我们想要的。我们看到的唯一问题是,在内容填充了
searchResultsTableView
之后,似乎当键盘最初被隐藏时,
searchResultsTableView
contentSize
比数据大得多,实际上似乎是键盘的大小。当我进入搜索栏,显示键盘并再次点击“搜索”(只是为了隐藏键盘)时,
contentSize
会正确调整,只填充屏幕,而不会更多。下面是我所说的初始
tableView
population的屏幕截图

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


有没有办法解决这个问题?

我遇到了这个问题。发布在开发者论坛上的解决方案对我很有效。不确定这是否是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];

}

这个系统错误仍然存在于iOS 8中,并且accept answer的解决方案不再有效。因此,您应该使用以下解决方案:

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

工作得很有魅力!但是,如果我在
viewDidLoad
中添加observer并在
dealoc
中删除它,我会感到非常困惑。内容和滚动指示器插图变为负片。不知道为什么会发生这种情况。对于iOS 8,你应该检查下面的@Allen answer。这非常有效!iOS 8上接受的答案将阻止tableview的底部滚动到视图中。