0

Why it doesn't show the contents of the cells in a UITableView filtered by a uisearchdisplaycontroller. In practice when I execute the search in the Searchbar, the cells are decoded correctly (in fact the number of cells sorted by the search is exact) but also configuring them in cellForRowAtIndexPath cell content is not shown (image and text). In addition, if I click on one of the cells searched, the exact way in prepareForSegue performs the transition to the corresponding viewController. So the problem is just that it doesn't show text and image in my cell.

Considering that the array configuration (array searchResults) is correct, I show you my method cellForRowAtIndexPath:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    NSString *identifier = @"MyCell";

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier];
    cell.backgroundView = [[UIImageView alloc] initWithImage:myImage];

    if ( cell == nil ) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier];
    }

    if (tableView == self.searchDisplayController.searchResultsTableView) {
        UIImage *profileSnap = myProfImage;


        NSString *name = [searchResults objectAtIndex:indexPath.row];

        UILabel *cellLabelName = (UILabel *)[cell viewWithTag:1];
        cellLabelName.text = name;

        UIImageView *cellImage = (UIImageView*)[cell viewWithTag:2];
        [cellImage setImage:profileSnap];

    }

    else{
    //here it all works

    UIImage *profileSnap = [self.arrProfileSnaps objectAtIndex:indexPath.row];
    NSString *name = [self.arrNames objectAtIndex:indexPath.row];

    UILabel *cellLabelName = (UILabel *)[cell viewWithTag:1];
    cellLabelName.text = name;

    UIImageView *cellImage = (UIImageView*)[cell viewWithTag:2];
    [cellImage setImage:profileSnap];

    }

    return cell;
Pinturikkio
  • 1,490
  • 1
  • 14
  • 28
  • Where are you populating searchResults? Did you verify that its assigning your variable name the correct value? `NSString *name = [searchResults objectAtIndex:indexPath.row];` – CoderPug Aug 24 '13 at 17:27
  • Show the code where you are populating your searchResults array. – Mundi Aug 24 '13 at 23:48
  • searchResults is populated correctly, I checked in debug and with NSLog. The problem is here – Pinturikkio Aug 25 '13 at 12:00

0 Answers0