UISearchDisplayController未显示任何单元格

时间:2010-08-13 00:30:15

标签: iphone objective-c cocoa-touch uisearchbar uisearchdisplaycontroller

我有一个UISearchDisplayController,可以在Interface Builder中正确连接。

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 { ... }

它总是进入其他条件。

我不确定为什么。

3 个答案:

答案 0 :(得分:1)

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

答案 1 :(得分:1)

使用以下内容。它应该工作。

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

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

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

    if ([tblView isEqual:[searchController searchResultsTableView]]) {
        return [self.searchResults count];
    }
...
}

答案 2 :(得分:0)

这是对这段代码的猜测,但我们是否正在研究搜索显示控制器本身?也许您的self.searchDisplayController.searchResultsTableView应该只是self.searchResultsTableView

如果不了解你的代表,我无法确定。

相关问题