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

标签 ios objective-c uitableview label

我有一个 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/

相关文章:

iOS 如何在最大震级未知时为热/冷频谱图选择颜色?

ios - 在 TableView 中移动行

通过 NSURLConnection sendAsynchronousRequest 下载 Ios 表格单元格图像会导致表格单元格删除时崩溃

android - Websocket 根据操作系统给出不同的数字

ios - 处理 iPhone 5、6 和 6 Plus 的高度和宽度尺寸(磅)

ios - 如何让我的应用程序出现在 UIActivityViewController 中以获取文本?

php - ASIFormDataRequest + PHP 问题

iphone - 在导航 Controller 中添加选项卡栏 Controller 时隐藏后退按钮

ios - 匹配单击的 TableView 行(字符串)以找到对应的唯一 ID

ios - 如何为 iOS 应用程序添加启动视频