gpt4 book ai didi

ios - UITableView 显示 'phantom cell'

转载 作者:行者123 更新时间:2023-11-29 10:55:39 26 4
gpt4 key购买 nike

在某些情况下,在我的表格单元格中,图像会添加到单元格中。我的单元格显示不正确。这是我的意思的图片:

enter image description here

第二个锁图标不属于那里……我不确定它是如何或为什么会在那里结束的。在此示例中,数组的计数为 2,因此附加锁甚至不在单元格内。

这不会在初始加载时发生,但会在单元格第一次重新加载时发生。这也让我感到困惑,因为初始加载函数与重新加载函数相同。

这是单元格本身的代码:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [UITableViewCell configureFlatCellWithColor:[UIColor greenSeaColor] selectedColor:[UIColor wetAsphaltColor] reuseIdentifier:CellIdentifier inTableView:(UITableView *)tableView];

if (!cell) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier];
[cell configureFlatCellWithColor:[UIColor greenSeaColor] selectedColor:[UIColor wetAsphaltColor]];

}

Room *room;

//is data filtered?
if(isFiltered)
room = [filteredTableData objectAtIndex:indexPath.row];
else
room = [roomList objectAtIndex:indexPath.row];


cell.textLabel.text = room.roomName;
cell.detailTextLabel.text = room.hostUsername;

//lock icon or not
if(room.password != nil)
{
UIImageView *pw = [[UIImageView alloc] initWithImage:img];
pw.tag = [room.rid integerValue];
[pw setImage:img];
pw.frame = CGRectMake(cell.frame.size.width - cell.frame.size.height, cell.frame.origin.y,
cell.frame.size.height - 2, cell.frame.size.height - 2);
[cell.contentView addSubview:pw];
}
else{ //remove the content view if not needed
[[cell.contentView viewWithTag:[room.rid integerValue]] removeFromSuperview];
}


return cell;
}

郑重声明,这不会发生在 iOS7 中(我知道这是保密协议(protocol),但如果有帮助,我只想提一下这个事实)。

最佳答案

重复使用的单元格上没有清除图标,所以如果没有密码,请删除 pw View

if(room.password != nil)
{
...
pw.tag = 12345;
} else {
[[cell.contentView viewWithTag:12345] removeFromSuperView];
}

当然,我建议您将此 View 分配给单元格的 accessoryView 而不是像现在这样,但这会回答您的问题。查看docs有关 accessoryView

的更多信息

关于ios - UITableView 显示 'phantom cell',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18541782/

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