2

我有一个在 Interface Builder 中正确连接的 UISearchDisplayController。

delegate = Files Owner
searchBar = Search Bar
searchContentsController = Files Owner
searchResultsDataSource = Files Owner
searchResultsDelegate = Files Owner

当我的 UITableView 调用时numberoOfRowsInSection:返回正确的号码。

但是,我的细胞cellForRowAtIndexPath:甚至没有达到:

- (UITableViewCell *)tableView:(UITableView *)tblView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{

 if (tblView == searchController.searchResultsTableView){
  NSLog(@"search will go here");
  UITableViewCell* cell = [self provideSearchQueryCells:tblView identifer:@"searchQueryCell"];
  STSymbol *aSymbol = [self.searchQueryResults objectAtIndex:indexPath.row];

  cell.textLabel.text = aSymbol.symbol;
  cell.detailTextLabel.text = aSymbol.symbol_title;

  return cell;
 }
 else { ... }

它总是进入 else 条件。

我不确定为什么。

4

3 回答 3

1

我需要创建一个 UISearchDisplayController 的实例,而不是使用 self.searchDisplayController。

于 2010-08-13T15:00:09.623 回答
1

使用以下。它应该工作。

 if ([tblView isEqual:[searchController searchResultsTableView]]) {
...
}

您还应该确保搜索结果行数正确,如下所示:

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{

    if ([tblView isEqual:[searchController searchResultsTableView]]) {
        return [self.searchResults count];
    }
...
}
于 2012-03-22T07:14:17.247 回答
0

这是对代码的近距离猜测,但我们是否正在查看搜索显示控制器本身?也许你self.searchDisplayController.searchResultsTableView应该只是self.searchResultsTableView

如果不认识您的代表,我无法确定。

于 2010-08-13T00:53:07.153 回答