3
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
   // NSString *CellIdentifier = [NSString stringWithFormat:@"cell%d",indexPath.row];

     static NSString *CellIdentifier = @"Cell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];

    if (cell == nil)
    {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
        }
    //clear all the cells subview before drawing the cell
    for(UIView *view in cell.contentView.subviews)
    {
        if ([view isKindOfClass:[UIView class]])
        {
            [view removeFromSuperview];
        }
    }

    if (arrPlaceId.count>0)
    {


        lblPlacename=[[UILabel alloc]initWithFrame:CGRectMake(30, 3, 300, 20)];
        lblPlacename.font=[UIFont fontWithName:@"arial" size:15];
        lblPlacename.textColor=[UIColor whiteColor];

        lblPlacename.backgroundColor=[UIColor clearColor];

        lblAddress=[[UILabel alloc]initWithFrame:CGRectMake(30, 20, 300, 18)];
        lblAddress.font=[UIFont fontWithName:@"arial" size:15];
        lblAddress.textColor=[UIColor whiteColor];

        lblAddress.backgroundColor=[UIColor clearColor];


        lblPlacename.text=[arrPlaceName objectAtIndex:indexPath.row];
        lblAddress.text=[arrPlaceAddress objectAtIndex:indexPath.row];


        [cell addSubview:lblPlacename];
        [cell addSubview:lblAddress];
    }



    return cell;
}
4

1 回答 1

0

将此添加到您的方法中

for(id obj in cell.contentView.subviews)
    {
        if([obj isKindOfClass:[UILabel class]])
        {
            [obj removeFromSuperview];
        }
    }

代替

for(UIView *view in cell.contentView.subviews)
    {
        if ([view isKindOfClass:[UIView class]])
        {
            [view removeFromSuperview];
        }
    }
于 2013-10-07T08:21:03.750 回答