我有一个分组表视图,它使用两个不同的自定义表格单元格。
当我滚动表格以使一个(或多个)单元格高于或低于可见区域时,这些单元格变为空白。当我向上(或向下)向上滚动以查看这些单元格时,它们仍然是空白的。为什么是这样?当细胞首次加载时,细胞显示出适当的含量。
以下是在指定的indexPath处加载单元格的代码:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
if(indexPath.section==0)
{
FMLFullTextCell = (FullTextCell *) [tableView dequeueReusableCellWithIdentifier:FullTextCell_ID];
if(FMLFullTextCell==nil)
{
[[NSBundle mainBundle]loadNibNamed:@"FullTextCell" owner:self options:nil];
[FMLFullTextCell initWithFMLText:@"Here is some demo fml text"];
}
return FMLFullTextCell;
}
else
{
FMLAuthorCell=(Author *)[tableView dequeueReusableCellWithIdentifier:AuthorCell_ID];
if(FMLAuthorCell==nil)
{
[[NSBundle mainBundle]loadNibNamed:@"Author" owner:self options:nil];
[FMLAuthorCell initWithTitle:@"Author" initWithAuthor:@"JohnnyAuthor"];
}
return FMLAuthorCell;
}
}
答案 0 :(得分:2)
您没有提供足够的信息来回答这个问题。
通常,UITableViewCells在通过initWithFrame:reuseIdentifier:
创建并通过dequeueReusableCellWithIdentifier:
加入时进行缓存。我的猜测是,你没有为两个不同的自定义表格单元指定不同的重用标识符,因此它们会以某种方式混合在你的代码中。这可能会导致所描述的行为。
无论如何,没有看到一些代码,这很难回答。您至少应该向我们展示数据源的tableView:cellForRowAtIndexPath
方法。