UISearchDisplayController的searchResultsTableView的ContentSize不正确。 iOS 7中的错误? [英] UISearchDisplayController's searchResultsTableView's ContentSize is incorrect. Bug in iOS 7?

查看:230
本文介绍了UISearchDisplayController的searchResultsTableView的ContentSize不正确。 iOS 7中的错误?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

The below problem only occurs on an iOS 6.0/6.1 application running on an iOS 7.0+ device.

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

So I have a UISearchDisplayController that searches our API and returns data. This all works, and everything is displayed as we want. The only problem we are seeing is that after the content has populated the searchResultsTableView, it seems as though when the keyboard is initially hidden, the contentSize of the searchResultsTableView is much larger than the data, and actually seems to be the size of the keyboard. When I enter the search bar, and show the keyboard and hit 'Search' again (just to hide the keyboard), the contentSize then adjusts correctly to only fill the screen, and nothing more. Below is a screen shot of what I am talking about with the initial tableView population.

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

The white is the table data, and the gray/cream color is the extra tableView space.

关于如何解决这个问题的想法?

Any ideas on how to fix this?

推荐答案

我遇到了这个问题。发布论坛上发布的解决方案此处为我工作。不确定这是iOS 7中的错误,还是他们改变了他们做事的方式,但这是我找到解决问题的唯一解决方案。

I had this exact problem. The solution posted on the developer forums here worked for me. Not sure if it's a bug in iOS 7 or just that they changed the way they're doing things but this is the only solution that I found solved my problem.

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

Solution from the forum post for the lazy:

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

}

这篇关于UISearchDisplayController的searchResultsTableView的ContentSize不正确。 iOS 7中的错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆