gpt4 book ai didi

iphone - 自定义 UITableViewCell 变空的问题?

转载 作者:行者123 更新时间:2023-12-03 17:45:51 24 4
gpt4 key购买 nike

我有一个分组表格 View ,它使用两个不同的自定义表格单元格。

当我滚动表格以使一个(或多个)单元格位于可见内容之上或之下时,这些单元格将变为空白。当我向上(或向下)滚动以查看这些单元格时,它们仍然是空白的。为什么是这样?首次加载时,单元格显示适当的内容。

以下是加载指定索引路径处的单元格的代码:

- (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;
}

}

最佳答案

您没有提供足够的信息来回答此问题。

通常,UITableViewCells 在通过 initWithFrame:reuseIdentifier: 创建并通过 dequeueReusableCellWithIdentifier: 访问时会被缓存。我的猜测是,您没有为两个不同的自定义表格单元指定不同的重用标识符,因此它们会以某种方式混合在您的代码中。这可能会导致所描述的行为。

无论如何,在没有看到一些代码的情况下,这个问题很难回答。您至少应该向我们展示数据源的 tableView:cellForRowAtIndexPath 方法。

关于iphone - 自定义 UITableViewCell 变空的问题?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/717349/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com