滚动后UITableView自定义单元格图像消失。

我正在创建我的开放网格视图。

我创建了一个自定义单元格,如下所示:

在此处输入图像描述

我像这样填充它:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *MyIdentifier = @"Cell"; TableGalleryCustomCell *cell = (TableGalleryCustomCell*)[tableView dequeueReusableCellWithIdentifier:MyIdentifier]; if( cell == nil) { NSArray *topLevelObjects = [[NSBundle mainBundle] loadNibNamed:@"TableGalleryCustomCell" owner:nil options:nil]; for (id currentObject in topLevelObjects) { if ([currentObject isKindOfClass:[UITableViewCell class]]) { cell = (TableGalleryCustomCell*)currentObject; break; } } } if (countingIndex < [[[self.appDelegate rssParser] rssItems] count]) { cell.firstAddress.text = [[[[self.appDelegate rssParser] rssItems] objectAtIndex:countingIndex] Address]; cell.firstPrice.text = [[[[self.appDelegate rssParser] rssItems] objectAtIndex:countingIndex] Deposit]; if ([[[[[[self appDelegate] rssParser]rssItems]objectAtIndex:countingIndex] imageURLs] count] != 0 ) { [cell.firstImage setImageWithURL:[NSURL URLWithString:[[[[[self.appDelegate rssParser] rssItems] objectAtIndex:countingIndex] imageURLs] objectAtIndex:0.0]]]; cell.firstImage.tag = countingIndex; } } countingIndex++; if (countingIndex < [[[self.appDelegate rssParser] rssItems] count]) { cell.secondAddress.text = [[[[self.appDelegate rssParser] rssItems] objectAtIndex:countingIndex] Address]; cell.secondPrice.text = [[[[self.appDelegate rssParser] rssItems] objectAtIndex:countingIndex] Deposit]; if ([[[[[[self appDelegate] rssParser]rssItems]objectAtIndex:countingIndex] imageURLs] count] != 0 ) { [cell.secondImage setImageWithURL:[NSURL URLWithString:[[[[[self.appDelegate rssParser] rssItems] objectAtIndex:countingIndex] imageURLs] objectAtIndex:0.0]]]; cell.secondImage.tag = countingIndex; } } countingIndex++; if (countingIndex < [[[self.appDelegate rssParser] rssItems] count]) { cell.thirdAddress.text = [[[[self.appDelegate rssParser] rssItems] objectAtIndex:countingIndex] Address]; cell.thirdPrice.text = [[[[self.appDelegate rssParser] rssItems] objectAtIndex:countingIndex] Deposit]; if ([[[[[[self appDelegate] rssParser]rssItems]objectAtIndex:countingIndex] imageURLs] count] != 0 ) { [cell.thirdImage setImageWithURL:[NSURL URLWithString:[[[[[self.appDelegate rssParser] rssItems] objectAtIndex:countingIndex] imageURLs] objectAtIndex:0.0]]]; cell.thirdImage.tag = countingIndex; } } countingIndex++; if (countingIndex < [[[self.appDelegate rssParser] rssItems] count]) { cell.fourthAddress.text = [[[[self.appDelegate rssParser] rssItems] objectAtIndex:countingIndex] Address]; cell.fourthPrice.text = [[[[self.appDelegate rssParser] rssItems] objectAtIndex:countingIndex] Deposit]; if ([[[[[[self appDelegate] rssParser]rssItems]objectAtIndex:countingIndex] imageURLs] count] != 0 ) { [cell.fourthImage setImageWithURL:[NSURL URLWithString:[[[[[self.appDelegate rssParser] rssItems] objectAtIndex:countingIndex] imageURLs] objectAtIndex:0.0]]]; cell.fourthImage.tag = countingIndex; } } countingIndex++; return cell; } 

它有点乱,但它工作…..直到我滚动。 加载图像后,滚动屏幕,图像消失。

我相信它可能是由于细胞的imageViews丢失了?

我尝试了完全相同的实现,但每个单元格中只有1个imageView,并且一切都很好。

任何正确方向的点都会非常感激。

我感谢您的帮助,感谢您的时间。

我相信问题是因为你的单元格正在出列,你在tableView:cellForRowAtIndexPath:中填充单元格tableView:cellForRowAtIndexPath:使用indexPath.row以外的行信息。

也许尝试以下几点:

 - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { NSArray * rssItems; id rssItem; static NSString * MyIdentifier = @"Cell"; TableGalleryCustomCell *cell = (TableGalleryCustomCell*)[tableView dequeueReusableCellWithIdentifier:MyIdentifier]; if( cell == nil) { NSArray *topLevelObjects = [[NSBundle mainBundle] loadNibNamed:@"TableGalleryCustomCell" owner:nil options:nil]; for (id currentObject in topLevelObjects) { if ([currentObject isKindOfClass:[UITableViewCell class]]) { cell = (TableGalleryCustomCell*)currentObject; break; } } } rssItems = [[self.appDelegate rssParser] rssItems]; if (indexPath.row < [rssItems count]) { rssItem = [rssItems objectAtIndex:indexPath.row]; cell.firstAddress.text = [rssItem Address]; cell.firstPrice.text = [rssItem Deposit]; if ([[rssItem imageURLs] count] != 0 ) { [cell.firstImage setImageWithURL:[NSURL URLWithString:[[rssItem imageURLs] objectAtIndex:0.0]]]; cell.firstImage.tag = indexPath.row; } } return cell; } 

分享我的经验:

有类似的问题。 我在应用程序中有很多表,其中一个数据会随机消失,最终整个表都会消失。

对我来说问题是我出列了细胞,给所有细胞带来了同样的“独特”。 因此,几个表共享相同的ID,我相信它们是相互冲突的,并且弄乱了我正在查看的单元格。

给每个表它自己的唯一标识符为我解决了问题。 (大新!)