gpt4 book ai didi

iPhone SDK : Setting the size of UISearchDisplayController's table view

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

我的应用程序的表格 View 不占据整个屏幕高度,因为我允许底部有 50 像素的横幅。

当我开始在搜索栏中输入内容时,搜索结果表格 View 会变大;它填充了搜索栏和选项卡栏之间的所有可用屏幕空间。这意味着最后的搜索结果被横幅遮盖了。

如何指定 UISearchDisplayController 使用的 TableView 的大小?我看不到任何边界或框架属性。

编辑以添加屏幕截图:

这就是 IB 中 TableView 的设置方式。它结束于距离合成标签栏 50px 的地方。

alt text
(来源:lightwood.net)

这是内容正常显示的方式。我已经滚动到这里的最底部。 alt text
(来源:lightwood.net)

这是搜索时的显示方式。我再次滚动到最底部。如果我禁用横幅广告,我可以看到搜索显示表直接向下延伸到标签栏。

alt text
(来源:lightwood.net)

最佳答案

解决这个问题的关键是找出何时更改表格 View 的几何形状。调用:

[self.searchDisplayController.searchResultsTableView setFrame:someframe];

创建 UISearchDisplayController 之后是徒劳的。答案是这个委托(delegate)方法:

-(void)searchDisplayController:(UISearchDisplayController *)controller didShowSearchResultsTableView:(UITableView *)tableView {
tableView.frame = someframe;
}

注意,我也尝试过 -searchDisplayController:didLoadSearchResultsTableView 但效果不佳。您必须等到它显示才能调整其大小。

另请注意,如果您简单地指定tableView.frame = otherTableView.frame,则搜索结果表格会与其对应的搜索栏重叠,因此无法清除或取消搜索!

我的最终代码如下所示:

-(void)searchDisplayController:(UISearchDisplayController *)controller didShowSearchResultsTableView:(UITableView *)tableView {

CGRect f = self.masterTableView.frame; // The tableView the search replaces
CGRect s = self.searchDisplayController.searchBar.frame;
CGRect newFrame = CGRectMake(f.origin.x,
f.origin.y + s.size.height,
f.size.width,
f.size.height - s.size.height);

tableView.frame = newFrame;
}

关于iPhone SDK : Setting the size of UISearchDisplayController's table view,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2388906/

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