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

标签 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 消失。如果删除最后一行的特殊代码 - 一切正常,为什么会这样?

最佳答案

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

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

关于ios - 滚动后自定义 TableView 单元格中的标签消失,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21810122/

相关文章:

ios - 如何解决IOS中的auth错误“重定向URI与注册的重定向URI不匹配”?

javascript - 在 Xamarin.Forms IOS WebViewRenderer 中调用 JavaScript 函数

ios - 取消 IBAction 的滑动手势触发 Segue

ios - Quickblox 视频聊天用户列表未加载

ios - Swift - 为 TableView 设置最大行数并删除最旧的行以便为新行让路

iphone - 如何在 Interface Builder 中创建 NSToggleButton?

ios - GrowingTextView 或 UItableview 单元格内的可扩展 TextView

iphone - 刷新/重新加载 uipicker

iphone - UINavigationController 逻辑中 searchDisplayController.searchResultsTableView 的行为

iOS - GCD 对 self 的弱引用和强引用