UISearchDisplayController更改行高 [英] UISearchDisplayController changing row height

查看:100
本文介绍了UISearchDisplayController更改行高的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Interface Builder中将 UITableView 行高设置为54.0。我在该视图上有一个 UISearchDisplayController 。当用户点击其中的搜索栏时,表格会正确调整大小。但是,当他们开始键入(并实际进行搜索)时,行高度会降低。在搜索点击取消之前,它会出错。

I've set my UITableView row height to in Interface Builder to 54.0. I have a UISearchDisplayController on that view. When the user taps the search bar in it, the table resizes properly. However, when they start typing (and actually doing the search) the row height decreases. It stays wrong until the search taps Cancel.

我在Apple网站上找不到有关此行为的文档。

I could find no documentation on this behavior on Apple's site.

我尝试在 UISearchDisplayDelegate 委托调用中设置行高。这可能是正确的方法,但我不知道细节,也无法使其发挥作用。

I've tried setting the row height in UISearchDisplayDelegate delegate calls. This might be the right approach, but I don't know the details and couldn't get it to work.

我也尝试过实施 - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath; 。这很有效,但我在此列表中有数千条目,并且无法获得性能提升。

I've also tried implementing - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath;. This worked, but I have thousands of entries in this list and can't take the performance hit.

解决此问题的正确方法是什么?

What's the right way to fix this?

推荐答案

正确的方法是使用以下代理。

The correct way to do this is to use the following delegate.

- (void)searchDisplayController:(UISearchDisplayController *)controller didLoadSearchResultsTableView:(UITableView *)tableView
{
    tableView.rowHeight = 54.0f; // or some other height
}

时调用它UITableView 已创建或显示。

如果您碰巧调用 searchDisplayController.searchResultsTableView in其他代码在没有执行搜索时,会提前创建UITableView。如果您使用 willShow 委托方法设置 rowHeight ,它将错过更改时间(由于某种原因)如果事先创建了tableView,则为rowHeight。

If you happen to call searchDisplayController.searchResultsTableView in other code when a search is not being performed, it will create the UITableView in advance. If you use the willShow delegate method to set the rowHeight, it will miss the timing (for some reason) to change the rowHeight if the tableView has been created beforehand.

这篇关于UISearchDisplayController更改行高的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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