滚动后单元格变空。 (Xcode中)

我的tableview有问题。 当我滚动并且单元格从屏幕上消失时,它变为空白。 我在故事板中构建了一个带有两个标签和一个imageview的原型单元,它与我在代码中使用的标识符相同。 我还为customcell构建了一个自定义类。 这是cellForRowAtIndexPath中的代码:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *CellIdentifier = @"Cell"; Scientist *currentScientist = [[xmlParser data] objectAtIndex:indexPath.row]; CustomCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; if (cell == nil) { cell = [[CustomCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier]; } cell.self.cellName.text = currentScientist.self.name; cell.self.cellSubject.text = currentScientist.self.subject; cell.self.cellImage.image = currentScientist.self.image; return cell; } 

我不知道你是否需要更多的代码来帮助我。

我发现了一篇详细说明您遇到的问题的文章。 我还建议打印出Scientist数据,以确保使用objectAtIndex:indexPath.row调用正确获取对象。

从我在下面链接的文章中,我愿意打赌你的dequeueReusableCellWithIdentifier是问题所在。 您可以通过给每个单元格提供其自己唯一的单元标识符(仅用于测试理论)来快速解决此问题。 但是,通过更改cellForRowAtIndex方法,找到解决此问题的合适方法。

资源

在我的情况下,为每个创建一个不同的单元格标识符工作得很好。 我有类似的东西:

 NSString *cellIdentifier = [NSString stringWithFormat:@"identifier%i%i", indexPath.section, indexPath.row]; 

其余的应该保持不变。