滚动后自定义 TableView 单元格中的标签消失 [英] Labels in custom TableView cells disappearing after scrolling

查看:31
本文介绍了滚动后自定义 TableView 单元格中的标签消失的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有带有自定义单元格的动态 tableView.CustomCell .h 文件如下所示:

I have dynamically tableView with custom cell. CustomCell .h file looks like this:

@property (strong, nonatomic) IBOutlet UILabel *uslugaName;  //I set retain doesn't work too
@property (strong, nonatomic) IBOutlet UILabel *howMuchPayLbl;

我的 CellForRowAtIndexPathMethod:

My CellForRowAtIndexPathMethod:

-(UITableViewCell *) tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

  static NSString * cellIdentifier = @"Cell";

    myCustomCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];


     /*
    if (!cell)
        cell = [[myCustomCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier];
    */

    if (indexPath.row !=15) {

    cell.uslugaName.text =serviceNameArr[indexPath.row];

    //окрашиваем ячейку в зависимости от активности услуги
    if ([uslugaIsActiveArr[indexPath.row]  isEqual: @"1"]) {
        cell.backgroundColor = [UIColor blackColor];
        cell.howMuchPayLbl.enabled = YES;
    }
    else {
        cell.backgroundColor = [UIColor grayColor];
        cell.howMuchPayLbl.enabled = NO;
    }

   if (![amountTmpArr[indexPath.row]  isEqual: @"0"])
       cell.howMuchPayLbl.text = [NSString stringWithFormat:@"Оплачиваю: %@ KZT", amountTmpArr[indexPath.row]];
}
    else {
        cell.uslugaName.font = [UIFont fontWithName:@"System Bold" size:16];
        cell.uslugaName.text = [NSString stringWithFormat:@"ОБЩАЯ СУММА ОПЛАТЫ: %@", fullAmount];
        cell.howMuchPayLbl.hidden = YES;
    }

    return cell;
}

我希望最后一行与其他行不同(为此:

I want that last row different than others ( for this purpose this:

if (indexPath.row !=15)

if (indexPath.row !=15)

).问题是 - 滚动 cell.howMuchPayLb 时消失.如果删除最后一行的特殊代码 - 一切正常,为什么会发生这种情况?

). Problem is - when scrolling cell.howMuchPayLb disappear. If delete special code for last row - all works ok, why this happening?

推荐答案

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

Your code has an if else statement where one branch can set cell.howMuchPayLbl.hidden = YES; but the other branch does not set cell.howMuchPayLbl.hidden = NO;. So, once the label is hidden it will never be un-hidden. When the cell with the hidden label is reused the label remains hidden.

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

Add cell.howMuchPayLbl.hidden = NO; (and any other 'inverse' configuration required) to your if statement.

这篇关于滚动后自定义 TableView 单元格中的标签消失的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆