iPhone SDK:设置UISearchDisplayController的表视图的大小

Chr*_*man 12 iphone uitableview uisearchdisplaycontroller

我的应用程序的表视图不占用全屏高度,因为我在底部允许50px的横幅.

当我开始在搜索栏中输入内容时,搜索结果表视图会更大; 它填充搜索栏和标签栏之间的所有可用屏幕空间.这意味着最后一个搜索结果被横幅遮挡了.

如何指定UISearchDisplayController使用的表视图的大小?我可以看到没有边界或框架属性.

编辑添加屏幕截图:

这是在IB中设置表视图的方式.它比合成标签栏短50px.

alt text http://iphone.lightwood.net/StackOverflow/gstableviewinib.png

这就是内容正常显示的方式.我已经滚到了最底层. alt text http://iphone.lightwood.net/StackOverflow/gstableviewatbottom.png

这是搜索时显示的方式.我再次滚动到最底层.如果我停用横幅广告,我会看到搜索显示表向下展开到标签栏.

alt text http://iphone.lightwood.net/StackOverflow/gssearchviewatbottom.png

Chr*_*man 51

解决这个问题的关键是找出何时更改表格视图的几何形状.呼叫:

[self.searchDisplayController.searchResultsTableView setFrame:someframe];
Run Code Online (Sandbox Code Playgroud)

在创建UISearchDisplayController之后是徒劳的.答案是这个委托方法:

-(void)searchDisplayController:(UISearchDisplayController *)controller didShowSearchResultsTableView:(UITableView *)tableView {
    tableView.frame = someframe;
}
Run Code Online (Sandbox Code Playgroud)

请注意,我也曾尝试-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;
}
Run Code Online (Sandbox Code Playgroud)