Я реализовал UISearchBar с UISearchDisplayController в контроллере Tableview, но я получаю следующий вопрос в нажав на строку поиска:IOS: UISearchBar с UISearchDisplayController разбился, нажав на SearchBar
провал утверждение - [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? –
Обновлен код, пожалуйста, обновите метод tableFor cellForRowAtIndexPath. –