UIImage显示在具有指定字符串值的单元格中

时间:2012-08-12 23:34:58

标签: iphone objective-c ios xcode

这篇文章在我的TableView中给出了奇怪的结果。我希望为重复的对象值为“标记”=“是”的单元格显示UIImage

这是什么代码?

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

1 个答案:

答案 0 :(得分:1)

问题是每次重复使用单元格时都需要清除imageView图像。

- (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"];
  }
}