UItableview可扩展单元格部分图像问题

时间:2014-11-28 10:38:24

标签: ios objective-c uitableview ios7 ios8

我有关于图像的截面图像的问题,当我展开单元格然后它在随机行中显示图像...

我必须在Section

中显示图像视图

图像+章节名称

我的问题是图片显示在一些随机的行中......

这里我的代码在哪里我错了?

    if (!indexPath.row)
    {
        // first row
        if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad)
        {
            client_Image = [[UIImageView alloc] initWithFrame:CGRectMake(10,10,50,50)];
            client_Image.image = [UIImage imageNamed:@"mdclogo.png"];
            [cell addSubview:client_Image];

            cell.textLabel.text =[NSString stringWithFormat:@"        %@",tclient.clientName];
            UIFont *fontBold = [UIFont fontWithName:@"Arial Rounded MT Bold" size:30];
            cell.textLabel.font  = fontBold;
            cell.textLabel.textColor = [UIColor blackColor];
        }
        else
        {
            cell.textLabel.text = [NSString stringWithFormat:@"        %@",tclient.clientName];
            UIFont *fontBold = [UIFont fontWithName:@"Arial Rounded MT Bold" size:20];
            cell.textLabel.font  = fontBold;
            cell.textLabel.textColor = [UIColor blackColor];
            client_Image = [[UIImageView alloc] initWithFrame:CGRectMake(5,5,39,36)];
            client_Image.image = [UIImage imageNamed:@"mdclogo.png"];
            [client_Image setClipsToBounds:YES];
            [cell addSubview:client_Image];
            cell.layer.cornerRadius = 0.5f;
            cell.layer.masksToBounds = YES;
        }
        // only top row showing
        if ([expandedSections containsIndex:indexPath.section])
        {
            cell.accessoryView = [DTCustomColoredAccessory accessoryWithColor:[UIColor grayColor] type:DTCustomColoredAccessoryTypeUp];
        }
        else
        {
            cell.accessoryView = [DTCustomColoredAccessory accessoryWithColor:[UIColor grayColor] type:DTCustomColoredAccessoryTypeDown];
        }
    }
    else
    {
        // all other rows (client flows)
        cell.textLabel.text = ((MDCFlowDetails * )[tclient.aflows getFlow:indexPath.row - 1]).title;
        if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad)
        {
            cell.indentationWidth = 2;
            UIFont *fontBold = [UIFont fontWithName:@"Arial" size:25];
            cell.textLabel.font  = fontBold;
            cell.accessoryView = nil;
            cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
        }
        else
        {
            cell.indentationWidth = 2;
            UIFont *myFont = [UIFont fontWithName:@"Arial" size: 16.0 ];
            cell.textLabel.font  = myFont;
            cell.accessoryView = nil;
            cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
        }
    }

1 个答案:

答案 0 :(得分:1)

当您因可重用性而滚动时,图像会添加到单元格中。试试下面的一个

 for (UIView *subview in [cell.contentView subviews]) 
{ 
  if ([subview isKindOfClass:[UIImageView class]]) 
     { 
     [subview removeFromSuperview]; 
    } 
}

您也可以使用tag

解决此问题