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

我有dynamictableView与自定义单元格。 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; } 

我想要最后一排不同于其他(为此目的:

如果(indexPath.row!= 15)

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

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

添加cell.howMuchPayLbl.hidden = NO; (和任何其他“反向”configuration要求)到你的if语句。

请参阅此链接将帮助你..因为dequeueReusableCellWithIdentifier不会识别具有相同名称的单元格标识。因此,您可以使用唯一的单元格标识像Cell1,Cell2 …为每一行。