0

I have implemented UISearchBar with UISearchdisplaycontroller in tableview controller but i getting the following issue in clicking on search bar:

Assertion failure in -[UISearchResultsTableView dequeueReusableCellWithIdentifier:forIndexPath:], /BuildRoot/Library/Caches/com.apple.xbs/Sources/UIKit_Sim/UIKit-3600.5.2/UITableView

I have set all delegate methods and using following code:

- (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)];


}

Code for cellForRowAtIndexPath is:

- (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;
}
Muhammad Umair
  • 583
  • 11
  • 32

1 Answers1

0

You're using the dequeueReusableCellWithIdentifier:forIndexPath: method. As per apple documents, you must register a class or nib file using the registerNib:forCellReuseIdentifier: or registerClass:forCellReuseIdentifier: method before calling this method. You have not registered a nib or a class for the reuse identifier "TransitionCell".

As per your code you seem to expect the dequeue method to return nil if it doesn't have a cell to give you. You need to use the dequeueReusableCellWithIdentifier: for that behavior:

METransitionTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
    cell = [[METransitionTableViewCell alloc]  initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];

    // Configure common elements here

}
Sahana Kini
  • 562
  • 2
  • 8