objective-c - 滚动后单元格变空。 (X代码)

标签 objective-c ios xcode uitableview

我的表格 View 有问题。当我滚动并且一个单元格从屏幕上消失时,它变成空白。我在 Storyboard中构建了一个带有两个标签和一个 ImageView 的原型(prototype)单元格,它具有与我在代码中使用的相同的标识符。我还为 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;
}

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

最佳答案

在我的例子中,为每个单元格创建一个不同的标识符效果很好。我有类似的东西:

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

其余的应该保持不变。

关于objective-c - 滚动后单元格变空。 (X代码),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12371300/

相关文章:

ios - UICollectionView 具有不同单元格的自动布局

ios - 在 UINavigationController 中设置图像时不显示图像

ios - 为什么我在 Objective C 中获取 NSString 的值,例如 0xb000000000000033

ios - Delphi XE5 iOS TidHTTP.get 获取旧版本的文件。也许缓存

ios - 使用 ejabberd(版本 2.1.6)在 iPhone 中推送通知延迟

xcode - 使用 Swift 在 tableView 中重新排序 Realm.io 数据

iphone - 使用自定义对象对数组进行排序

objective-c - 最适合扫描多个文件中的关键字(从 Cocoa 应用程序调用)的语言?

iphone - 在其他设备上测试我的 iPad 应用程序

ios - 如何在出现之前过滤ios推送通知