我的表格 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/