2

我有一個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 { ... } 

它總是轉到其他條件。

我不完全確定爲什麼。

回答

1

我需要創建一個UISearchDisplayController的實例,而不是使用self.searchDisplayController。

0

這是關於代碼中的這種關閉的猜測,但是我們是否正在尋找搜索顯示控制器本身?也許你的self.searchDisplayController.searchResultsTableView應該是self.searchResultsTableView

我無法確定不知道您的代表。

+0

我相信是這樣的,因爲這個代碼在一個UITableViewController子類。 self.searchResultsTableView不是UITableViewController中的屬性。 – 2010-08-13 04:48:44

+0

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

1

使用以下內容。它應該工作。

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