Iphone UISearchDisplayController未显示任何单元格
我有一个在Interface Builder中正确连接的UISearchDisplayControllerIphone UISearchDisplayController未显示任何单元格,iphone,objective-c,cocoa-touch,uisearchbar,uisearchdisplaycontroller,Iphone,Objective C,Cocoa Touch,Uisearchbar,Uisearchdisplaycontroller,我有一个在Interface Builder中正确连接的UISearchDisplayController delegate = Files Owner searchBar = Search Bar searchContentsController = Files Owner searchResultsDataSource = Files Owner searchResultsDelegate = Files Owner 当my UITableView调用NumberRowsInSection
delegate = Files Owner
searchBar = Search Bar
searchContentsController = Files Owner
searchResultsDataSource = Files Owner
searchResultsDelegate = Files Owner
当my UITableView调用NumberRowsInSection:
时,将返回正确的号码
但是,cellforrowatinexpath:
中的我的单元格甚至无法到达:
- (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条件
我不太清楚原因。这是对代码的一个猜测,但我们是在看搜索显示控制器本身吗?也许您的
self.searchDisplayController.searchResultsTableView
应该是self.searchResultsTableView
如果不了解您的委托,我无法确定。我需要创建UISearchDisplayController的实例,而不是使用self.searchDisplayController。使用以下命令。它应该会起作用
if ([tblView isEqual:[searchController searchResultsTableView]]) {
...
}
您还应确保搜索结果行数正确,如下所示:
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
if ([tblView isEqual:[searchController searchResultsTableView]]) {
return [self.searchResults count];
}
...
}
我相信是这样,因为这段代码位于UITableViewController子类中。self.searchResultsTableView不是UITableViewController中的属性。我修改了我的帖子,以显示代理在IB中的连接方式。