我在的tableview控制器实现的UISearchBar与UISearchdisplaycontroller,但我发现了以下问题点击搜索栏:iOS版:的UISearchBar与UISearchdisplaycontroller坠毁通过点击搜索栏
断言失败 - [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;
}
,但如果我们点击它的UISearchBar崩溃..我怎么给CellIdentifier到UISearchDisplayController? –
更新了代码,请更新您的tableview cellForRowAtIndexPath方法 –