ingenspor
ingenspor

Reputation: 932

UIImage displayed in cells with specified string value

This piece gives strange results in my TableView. I want the UIImage displayed for the cells where the reprecented objects value for key "Marked" = "Yes".

What is the correct code for this?

if ([[[sortedObjects objectAtIndex: indexPath.row] valueForKey:@"Marked"] isEqual:@"Yes"])  
{
    cell.markedImageView.image = [UIImage imageNamed:@"markedItem.png"];
}

Upvotes: 1

Views: 44

Answers (1)

bbarnhart
bbarnhart

Reputation: 6710

The problem is that you need to clear the imageView image each time the cell is reused.

- (void)configCell:(MyCustomCell *)cell atIndexPath:(NSIndexPath)indexPath
{
  cell.markedImageView.image = nil;

  // configure cell normally

  if ([[[sortedObjects objectAtIndex: indexPath.row] valueForKey:@"Marked"] isEqual:@"Yes"])  
  {
    cell.markedImageView.image = [UIImage imageNamed:@"markedItem.png"];
  }
}

Upvotes: 1

Related Questions