UISearchDisplayController不显示任何单元格

问题描述:

我有一个UISearchDisplayController正确连接在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 { ... } 

它总是转到其他条件。

我不完全确定为什么。

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

这是关于代码中的这种关闭的猜测,但是我们是否正在寻找搜索显示控制器本身?也许你的self.searchDisplayController.searchResultsTableView应该是self.searchResultsTableView

我无法确定不知道您的代表。

+0

我相信是这样的,因为这个代码在一个UITableViewController子类。 self.searchResultsTableView不是UITableViewController中的属性。 – 2010-08-13 04:48:44

+0

我修改了我的帖子,以显示代表如何在IB中联系。 – 2010-08-13 05:23:48

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

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

,你也应该确保搜索结果行数是正确的,因为在:

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

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

这不起作用 – 2012-03-22 07:50:45