自定义TableView单元格中的标签在滚动后消失

时间:2014-02-16 10:46:54

标签: ios iphone objective-c uitableview

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

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

我的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;
}

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

  

if(indexPath.row!= 15)

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

2 个答案:

答案 0 :(得分:9)

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

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

答案 1 :(得分:0)

参考此link将帮助您.. 由于dequeueReusableCellWithIdentifier,它不会识别具有相同名称的细胞识别。因此,您可以为每一行使用Cell1,Cell2等独特的细胞识别..

相关问题