1

我在我的 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

4

2 回答 2

5

事实证明,这是一个尺寸问题。我找到了一个教程,在设置中放置了以下代码:

[theSearchBar sizeToFit];

这让一切看起来都很完美。

由于UISearchDisplayController使用已经建立的UISearchBar它并不能消除问题。

于 2010-01-29T15:06:02.517 回答
0

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

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

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

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

self.searchDisplayController=searchController;

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

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

于 2010-01-29T06:20:33.880 回答