UITableView中的单元子视图重复问题

时间:2014-08-28 07:08:40

标签: ios objective-c iphone

我有一个自定义单元格,带有显示某些信息的徽章。我想仅为某些单元格设置徽章图像和文本(取决于我从Web服务响应获得的某些标记)。但是当我重复使用单元格时,徽章及其文本就会重复出现。怎么解决。

徽章及其文本是自定义单元格的一部分,不会通过代码添加为子视图。

- (void) setBadgeText:(VBMerchantDealCell *)cell withObject:(VBDeals *)deals{


    if ([deals.dealType intValue] == PUNCHCARDDEAL) {
        if ([deals.punchStatus intValue] == UNIV_INDEX_ONE && ![VBUtility isNullValue:deals.punchSpecialMessage]) {
            [cell.lblBadgeLabel  setText:deals.punchSpecialMessage];
        }else {
            [cell.lblBadgeLabel setText:[self getBadgeTextForPCD:deals]];

        }
        return;
    }
}

1 个答案:

答案 0 :(得分:0)

尝试以下方法:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
  {
      // Cell configurations
      [self setBadgeText:indexPath :deals];
      return cell;
  }
- (void) setBadgeText:(NSIndexPath *)indexPath withObject:(VBDeals *)deals
  {
    [self.tableView beginUpdates];
    YourTableViewCell *cell = [self.tableView dequeueReusableCellWithIdentifier:@"cellIdentifier" forIndexPath:indexPath];]
    if ([deals.dealType intValue] == PUNCHCARDDEAL) 
      {
        if ([deals.punchStatus intValue] == UNIV_INDEX_ONE && ![VBUtility isNullValue:deals.punchSpecialMessage]) 
           [cell.lblBadgeLabel  setText:deals.punchSpecialMessage];
        else 
           [cell.lblBadgeLabel setText:[self getBadgeTextForPCD:deals]];
      }
    [self.tableView endUpdates];
  }