我已经在 tableview 控制器中使用 UISearchdisplaycontroller 实现了 UISearchBar,但是在单击搜索栏时出现以下问题:
-[UISearchResultsTableView dequeueReusableCellWithIdentifier:forIndexPath:] 中的断言失败,/BuildRoot/Library/Caches/com.apple.xbs/Sources/UIKit_Sim/UIKit-3600.5.2/UITableView
我已经设置了所有委托方法并使用以下代码:
- (void)filterContentForSearchText:(NSString*)searchText scope:(NSString*)scope
{
NSPredicate *resultPredicate = [NSPredicate predicateWithFormat:@"projectName contains[c] %@", searchText];
_searchResults = [_searchResults filteredArrayUsingPredicate:resultPredicate];
}
-(BOOL)searchDisplayController:(UISearchDisplayController *)controller shouldReloadTableForSearchString:(NSString *)searchString
{
[self filterContentForSearchText:searchString
scope:[[self.searchDisplayController.searchBar scopeButtonTitles]
objectAtIndex:[self.searchDisplayController.searchBar
selectedScopeButtonIndex]]];
return YES;
}
- (void)searchDisplayController:(UISearchDisplayController *)controller willShowSearchResultsTableView:(UITableView *)tableView {
[tableView setContentInset:UIEdgeInsetsMake(100, 0, 0, 0)];
}
代码cellForRowAtIndexPath
是:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"TransitionCell";
METransitionTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
if (cell == nil) {
cell = [[METransitionTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
// Configure common elements here
}
if (tableView == self.searchDisplayController.searchResultsTableView) {
//activeProject = [_searchResults objectAtIndex:indexPath.row];
} else {
}
NSString *transition = @"Test";
cell.cupponTitle.text = transition;
cell.favourtiesButton.tag = indexPath.row;
[cell.favourtiesButton addTarget:self action:@selector(favourtiesClicked:) forControlEvents:UIControlEventTouchUpInside];
return cell;
}