gpt4 book ai didi

ios - 重新加载/滚动表格时标签消失

转载 作者:行者123 更新时间:2023-11-29 00:25:44 24 4
gpt4 key购买 nike

我有一个 UITableview 和两个 UILabels 就像在聊天中一样。当可见的 UITableview 被填充并且当我添加额外的单元格时,我的 UILabel 消失了。

可能还有其他可见的 UILabels。只有那 2 个聊天 UILabels 是隐藏的。谁能建议我可能的解决方案?

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath;
{
ChatScreenViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"ChatCell" forIndexPath:indexPath];
index = indexPath.row + 1;
indexx = indexPath;


cell.ChatLabel1.layer.cornerRadius = 8;
cell.ChatLabel1.layer.masksToBounds = YES;
cell.ChatLabel2.layer.cornerRadius = 8;
cell.ChatLabel2.layer.masksToBounds = YES;

cell.ImageviewLabel1.layer.cornerRadius = 20;
cell.ImageviewLabel1.layer.masksToBounds = YES;
cell.ImageviewLabel2.layer.cornerRadius = 20;
cell.ImageviewLabel2.layer.masksToBounds = YES;
cell.ImageviewLabel2.backgroundColor = [UIColor greenColor];



if([Replychat[indexPath.row] valueForKey:@"bot"] != NULL)
{

cell.ChatLabel1.text = [Replychat[indexPath.row] valueForKey:@"bot"];
cell.ChatLabel2.hidden = YES;
cell.ImageviewLabel2.hidden = YES;

cell.TimeLabel1.text = TimeArray[indexPath.row];
}
else
{

cell.ChatLabel2.text = [Replychat[indexPath.row] valueForKey:@"User"];
cell.ChatLabel1.hidden = YES;
cell.ImageviewLabel1.hidden = YES;
cell.TimeLabel2.text = TimeArray[indexPath.row];
}

return cell;

最佳答案

Labels in custom TableView cells disappearing after scrolling

我的代码有一个 if else 语句,其中一个分支可以设置 cell.ChatLabel2.hidden = YES;但另一个分支没有设置 cell.ChatLabel2.hidden = NO;。因此,一旦标签被隐藏,它就永远不会被隐藏。当具有隐藏标签的单元格被重新使用时,标签将保持隐藏状态。

添加 cell.ChatLabel2.hidden = NO; (以及所需的任何其他“反向”配置)到您的 if 语句。

关于ios - 重新加载/滚动表格时标签消失,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43084568/

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