UISearchDisplayController 与 searchResultsTableView 和 self.tableView 的奇怪行为

问题描述:

这是我的故事板视图及其连接:

this is my storyboard view and it's connections:

http://i.stack.imgur.com/uD0pT.pnghttp://i.stack.imgur.com/FNnVa.png

在我的特定情况下,我有从第一个外部 Web 服务获取数据的 searchResultsTableView 和从另一个 Web 服务获取数据的 self.tableview.

In my specific case I have the searchResultsTableView that gets its data from the first external web service and the self.tableview that fetches data from another web service.

为了清楚起见,我添加了一些代码:

I add some code to be clear:

-(BOOL)searchDisplayController:(UISearchDisplayController *)controller shouldReloadTableForSearchString:(NSString *)searchString { ... }

这获取了第一个网络服务,特别是返回NO

this fetched the first web services, in particular return NO

还有一个:

[self.searchDisplayController.searchResultsTableView reloadData];

获取完成后重新加载数据.

to reload the data when the fetch is completed.

然后我们有:

-(void) doSearch:(NSString*) keyword inStore:(NSInteger) store getPage: (int) pagenum {..}

获取第二个 Web 服务并将结果设置在名为fetchedItems"的数组中

that fetches the second web service and set the results in an array called 'fetchedItems'

现在,为了管理这两个表,我必须编写这个方法:

Now, to manage this two tables I had to write this method:

- (void)searchBarSearchButtonClicked:(UISearchBar *)searchBar
{
  NSLog(@"Avvio ricerca..");
  // Do the search...
  NSInteger store = [self buttonSelected];
  [self doSearch:searchBar.text inStore:store getPage:1];
  [self.searchDisplayController setActive:NO];
}

我尝试不使用setActive:NO",但 self.searchDisplayController.searchTableView 仍然显示,我无法使用doSearch"结果设置下方"self.tableView

I tried without the 'setActive:NO' but the self.searchDisplayController.searchTableView remains displayed and I can't se the "underneath" self.tableView with the 'doSearch' results

好的.现在我有了这个方法:

Ok. Now I have this method:

    - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
    {
static NSString *CellIdentifier = @"foundCell";
      static NSString *suggestionCellIdentifier = @"suggestionCell";
      UITableViewCell *cell;


       if (tableView == self.searchDisplayController.searchResultsTableView) {
         // HERE I AM WITH SEARCHDISPLAYCONTROLLER    

         cell = [self.tableView dequeueReusableCellWithIdentifier:suggestionCellIdentifier];
         cell.textLabel.text = [self.suggestions objectAtIndex:indexPath.row];
      } else {
        // HERE I AM WITH SELF.TABLEVIEW

    }

    return cell;
}

现在可以了,但是有问题!当我点击带有结果的 tableview(由 self.tableview 表示)时,我无法使用该方法捕捉点击- (void) tableView: (UITableView *) tableView didSelectRowAtIndexPath: (NSIndexPath *) indexPath {...}

Now it works, but there's a problem! When i tap on the tableview with the results (denoted by self.tableview) I can't catch the tap with the method - (void) tableView: (UITableView *) tableView didSelectRowAtIndexPath: (NSIndexPath *) indexPath {...}

但我在编辑模式下重新打开了 uisearchdisplaycontroller(因此用户可以在搜索栏中点击)

我哪里错了?

已修复!使用时displaySearchBarInNavigationBar = YES我们需要搜索栏在故事板中的表格视图中!

fixed! When using displaysSearchBarInNavigationBar = YES we need that the searchbar is OUT for the tableview in the storyboard!