【问题标题】:Moving SearchBar table view移动 SearchBar 表格视图
【发布时间】:2013-12-27 06:17:43
【问题描述】:

我有一个搜索栏和一个搜索显示控制器,并实现了相关的方法。在我的xib 中,此搜索栏上方有一个文本字段。我希望表格视图出现在我的搜索栏下方,而不是覆盖搜索栏或其上方的文本字段。

我试过这个:

self.searchDisplayController.searchResultsTableView.frame = CGRectMake(0, 247, 320, 400);

但这似乎没有任何效果。如何设置UITableView 位置?

好的 - 这样做 -

- (void)searchDisplayController:(UISearchDisplayController *)controller didShowSearchResultsTableView:(UITableView *)tableView {
tableView.frame = CGRectMake(0, 200, 320, 400);

}

表格显示在搜索栏下方,但由于某种原因,我无法单击上方的文本字段。我认为这种情况正在发生,因为所述字段仍被表格视图覆盖,我认为这是因为当我单击搜索栏并开始输入时,会出现一个涵盖所有内容的灰色区域。

【问题讨论】:

  • 那个灰色区域应该是覆盖 UITableView 显示搜索结果。尝试从 xib 接口添加初始 tableView 并在 SearchDisplayController 方法中使用综合属性。

标签: ios cocoa-touch uisearchbar


【解决方案1】:

尝试在控制器中设置框架

- (void)searchDisplayController:(UISearchDisplayController *)controller didShowSearchResultsTableView:(UITableView *)tableView {
     if ( [controller.searchBar.superview isKindOfClass: [UITableView class]] )
 {
    UITableView* staticTableView = (UITableView*)controller.searchBar.superview;

    CGRect f = [tableView.superview convertRect: staticTableView.frame fromView: staticTableView.superview];
    CGRect s = controller.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;
 }
}

【讨论】:

    【解决方案2】:

    一个老问题,但我想我还是会回答,希望它可以帮助其他人 - 我有同样的问题,每当搜索字符串/结果更新时调用 scrollRect - 你需要对视图控制器的引用( self.displayController 在这种情况下)显示搜索结果。

        [self.displayController.tableView scrollRectToVisible:CGRectMake(0, 0, 1, 1) 
                                                     animated:NO];
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-10-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多