gpt4 book ai didi

iphone - UISearchDisplayController 更改行高

转载 作者:行者123 更新时间:2023-12-03 18:17:04 27 4
gpt4 key购买 nike

我已将 Interface Builder 中的 UITableView 行高设置为 54.0。我在该 View 上有一个 UISearchDisplayController 。当用户点击其中的搜索栏时,表格的大小会正确调整。然而,当他们开始输入(并实际进行搜索)时,行高会减小。在搜索点击取消之前,它一直是错误的。

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

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

我还尝试实现 - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath;。这有效,但我在此列表中有数千个条目,无法承受性能影响。

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

最佳答案

执行此操作的正确方法是使用以下委托(delegate)。

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

UITableView 时调用它创建或显示。

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

关于iphone - UISearchDisplayController 更改行高,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2639722/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com