【问题标题】:UISearchBar is covered up in a tableViewHeaderUISearchBar 被 tableViewHeader 覆盖
【发布时间】:2010-01-29 05:53:12
【问题描述】:

我在 UITableView.tableHeaderView 中放置了一个 UISearchBar。然而,它通过将可视顶部放置到第一节标题来覆盖 searchBar。当我向下拖动 tableView 时,我只能看到 searchBar。它被覆盖了一半,然后无法选择,因为释放 tableView 滚动会将橡皮筋带回视野之外。请帮忙。

下面是放在我的 UITableViewController viewDidLoad 方法中的:

UISearchBar *theSearchBar = [[UISearchBar alloc] init];
theSearchBar.delegate = self;
self.searchBar = theSearchBar;
[theSearchBar release];

self.tableView.tableHeaderView = self.searchBar;

结果如下截图:http://imagebin.ca/view/6qNiwHR.html

【问题讨论】:

    标签: uitableview iphone-sdk-3.0 uisearchbar


    【解决方案1】:

    原来是尺寸问题。我发现a tutorial 在设置中放置了以下代码:

    [theSearchBar sizeToFit];
    

    让一切看起来都很完美。

    由于UISearchDisplayController 使用已建立的UISearchBar,因此并不能消除问题。

    【讨论】:

      【解决方案2】:

      我认为 tableHeaderView 不是放置搜索栏的最佳位置。 我通常使用 UISearchDisplayController:

      searchController = [[UISearchDisplayController alloc]
                           initWithSearchBar:theSearchBar contentsController:self];
      searchController.delegate = self;
      searchController.searchResultsDataSource = self;
      searchController.searchResultsDelegate = self;
      

      它非常简单,并提供了一些搜索功能(您必须在委托/数据源中实现它们,在这种情况下是您的控制器)。

      我通常用笔尖来做,但我认为你只需要将它分配给你的视图控制器:

      self.searchDisplayController=searchController;
      

      如果不显示视图,你应该直接将视图添加到tableView中。

      你可以看看参考资料,或者问你有没有问题。

      【讨论】:

      • 非常感谢。甚至没有意识到有一个控制器。现在就去试试这个。
      • 至少从 3.0 开始,searchDisplayController 是只读属性,不能这样设置。
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2019-11-22
      • 2012-08-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-11-04
      • 2016-06-11
      相关资源
      最近更新 更多