iPhone SDK:设置UISearchDisplayController的表视图的大小 [英] iPhone SDK: Setting the size of UISearchDisplayController's table view
问题描述
我的应用程序的表格视图没有占据整个屏幕的高度,因为我在底部允许横幅为50px。
My app's table view does not occupy the full screen height, as I've allowed 50px at the bottom for a banner.
当我开始输入搜索内容时bar,搜索结果表视图更大;它填充搜索栏和标签栏之间的所有可用屏幕空间。这意味着最后一个搜索结果被横幅遮挡。
When I begin typing in the search bar, the search results table view is larger; it fills all available screen space between the search bar and the tab bar. This means that the very last search result is obscured by the banner.
如何指定UISearchDisplayController使用的表视图的大小?我可以看到没有边界或框架属性。
How do I specify the size of the table view used by UISearchDisplayController? There's no bounds or frame property that I can see.
编辑添加屏幕截图:
这是在IB中设置表格视图的方式。它比合成标签栏短50px。
This is how the table view is set up in IB. It ends 50px short of the synthesized tab bar.
alt text http ://iphone.lightwood.net/StackOverflow/gstableviewinib.png
这是内容正常显示的方式。我已经滚到了最底层。
替代文字http://iphone.lightwood.net/StackOverflow/gstableviewatbottom.png
This is how content displays normally. I've scrolled to the very bottom here. alt text http://iphone.lightwood.net/StackOverflow/gstableviewatbottom.png
这是搜索时显示的方式。我再次滚动到最底层。如果我停用横幅广告,我会看到搜索显示表向右展开到标签栏。
This is how it displays when searching. Again, I've scrolled to the very bottom. If I disable the banner ad, I can see that the search display table spreads right down to the tab bar.
替代文字http://iphone.lightwood.net/StackOverflow/gssearchviewatbottom.png
推荐答案
解决这个问题的关键是找出何时更改表格视图的几何形状。调用:
The key to solving this one was finding out when to change the geometry of the table view. Calling:
[self.searchDisplayController.searchResultsTableView setFrame:someframe];
是徒劳的。答案是这个委托方法:
after creating the UISearchDisplayController was futile. The answer was this delegate method:
-(void)searchDisplayController:(UISearchDisplayController *)controller didShowSearchResultsTableView:(UITableView *)tableView {
tableView.frame = someframe;
}
注意,我也试过 -searchDisplayController:didLoadSearchResultsTableView
但在那里没有任何好处。你必须等到显示它才能调整大小。
Note, I had also tried -searchDisplayController:didLoadSearchResultsTableView
but it did no good in there. You have to wait until it's displayed to resize it.
另请注意,如果你只是指定 tableView.frame = otherTableView.frame
,搜索结果表与其对应的搜索栏重叠,因此无法清除或取消搜索!
Also note that if you simply assign tableView.frame = otherTableView.frame
, the search results table overlaps its corresponding search bar, so it is impossible to clear or cancel the search!
我的最终代码如下所示:
My final code looked like this:
-(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:设置UISearchDisplayController的表视图的大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!