我有一个UIViewController
包含 aUITableView
和 a的类SearchDisplayController
。我面临的问题是,每当我单击搜索栏并键入查询时,它都会显示搜索结果并出于某种原因显示底层 UITableView。
例如,如果我在运行搜索时运行此代码:
- (UITableViewCell *)tableView:(UITableView *)tableView
cellForRowAtIndexPath:(NSIndexPath *)indexPath {
if (tableView == self.searchDisplayController.searchResultsTableView) {
..
NSLog(@"constructing a search result table view cell ");
} else
{
..
NSLog(@"::: constructing a mail box table view cell");
}
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
if (tableView == self.searchDisplayController.searchResultsTableView) {
NSLog(@"searchDisplayController: number of rows: %d", [queryResultData count]);
} else {
NSLog(@"mailbox: NUMBER OF ROWS: %d", [self.emailData count]);
}
}
日志将如下所示:
[5033:c07] performing search with query hi
[5033:c07] ftSearch started with query = hi dbNum = 0
[5033:c07] mailbox: NUMBER OF ROWS IN SECTION: 19
[5033:c07] ::: constructing a mail box table view cell
[5033:c07] ::: constructing a mail box table view cell
[5033:c07] ::: constructing a mail box table view cell
[5033:c07] ::: constructing a mail box table view cell
[5033:c07] mailbox: NUMBER OF ROWS IN SECTION: 19
[5033:c07] ::: constructing a mail box table view cell
[5033:c07] ::: constructing a mail box table view cell
[5033:c07] ::: constructing a mail box table view cell
[5033:c07] ::: constructing a mail box table view cell
[5033:c07] searchDisplayController: number of rows are 1
[5033:c07] ::: constructing a search result table view cell
[5033:c07] searchDisplayController: number of rows are 2
[5033:c07] ::: constructing a search result table view cell
[5033:c07] searchDisplayController: number of rows are 3
[5033:c07] ::: constructing a search result table view cell
[5033:c07] searchDisplayController: number of rows are 4
[5033:c07] ::: constructing a search result table view cell
[5033:c07] searchDisplayController: number of rows are 5
[5033:c07] mailbox: NUMBER OF ROWS IN SECTION: 19
[5033:c07] ::: constructing a mail box table view cell
[5033:c07] ::: constructing a mail box table view cell
[5033:c07] ::: constructing a mail box table view cell
[5033:c07] ::: constructing a mail box table view cell
[5033:c07] mailbox: NUMBER OF ROWS IN SECTION: 19
[5033:c07] searchDisplayController: number of rows are 6
[5033:c07] ::: constructing a mail box table view cell
[5033:c07] ::: constructing a mail box table view cell
[5033:c07] ::: constructing a mail box table view cell
[5033:c07] ::: constructing a mail box table view cell
[5033:c07] mailbox: NUMBER OF ROWS IN SECTION: 19
[5033:c07] ::: constructing a mail box table view cell
[5033:c07] ::: constructing a mail box table view cell
[5033:c07] ::: constructing a mail box table view cell
[5033:c07] ::: constructing a mail box table view cell
[5033:c07] mailbox: NUMBER OF ROWS IN SECTION: 19
[5033:c07] ::: constructing a mail box table view cell
[5033:c07] ::: constructing a mail box table view cell
[5033:c07] ::: constructing a mail box table view cell
[5033:c07] ::: constructing a mail box table view cell
[5033:c07] mailbox: NUMBER OF ROWS IN SECTION: 19
[5033:c07] ::: constructing a mail box table view cell
[5033:c07] ::: constructing a mail box table view cell
[5033:c07] ::: constructing a mail box table view cell
[5033:c07] ::: constructing a mail box table view cell
[5033:c07] mailbox: NUMBER OF ROWS IN SECTION: 19
[5033:c07] ::: constructing a mail box table view cell
[5033:c07] ::: constructing a mail box table view cell
[5033:c07] ::: constructing a mail box table view cell
[5033:c07] ::: constructing a mail box table view cell
[5033:c07] ::: constructing a mail box table view cell
[5033:c07] ::: constructing a mail box table view cell
[5033:c07] ::: constructing a mail box table view cell
[5033:c07] ::: constructing a mail box table view cell
这就是 IB 的样子:
和
要清楚.. 显示的 UI 正是我想要的.. 但我只是对为什么另一个表正在执行所有这些渲染计算感到困惑.. 这后来成为一个真正的问题 b/c 它给了我一些线程/asynchronous 代码令人头疼,在这种背景和不必要的活动发生时很难调试。
注意:我还尝试了 IB 的不同布局。我注意到的一件事是,如果我将搜索栏设置为 tableView 的相邻子视图 .. 基础表将被调用更多!
我还考虑过创建一个标志并检查搜索栏当前是否正在使用,然后基本上阻止底层的 UITableView 做任何工作..但这还不够好..它不应该首先被调用.
有人可以告诉我在使用搜索时如何防止基础表出现/呈现吗?