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

查看:22
本文介绍了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 之后,似乎当键盘最初隐藏时,searchResultsTableView<的 contentSize/code> 比数据大很多,实际上似乎是键盘的大小.当我进入搜索栏,并显示键盘并再次点击搜索"(只是为了隐藏键盘)时,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天全站免登陆