Iphone 删除tableview的所有子图像视图

Iphone 删除tableview的所有子图像视图,iphone,uitableview,subview,Iphone,Uitableview,Subview,我正在使用表格视图,并根据选项是否正确,将小图像(交叉箭头和接受箭头图像)添加到每个单元格的右侧 ..现在我的表多次重新加载…因此图像在每个单元格上重复 我的意思是,如果单元格_1有一个接受图像..在重新加载表之后,如果单元格_1的值发生了变化,它需要十字箭头图像…那么两个图像在那里都是可见的…(新图像在旧图像之上) 我想这是因为上次添加了子视图,但没有删除 请告诉我如何删除旧图像 下面是我在tableView的委托方法中将图像添加到单元格中的一些代码 UIImageView *image =[

我正在使用表格视图,并根据选项是否正确,将小图像(交叉箭头和接受箭头图像)添加到每个单元格的右侧

..现在我的表多次重新加载…因此图像在每个单元格上重复

我的意思是,如果单元格_1有一个接受图像..在重新加载表之后,如果单元格_1的值发生了变化,它需要十字箭头图像…那么两个图像在那里都是可见的…(新图像在旧图像之上)

我想这是因为上次添加了子视图,但没有删除

请告诉我如何删除旧图像

下面是我在tableView的委托方法中将图像添加到单元格中的一些代码

UIImageView *image =[[UIImageView alloc]initWithFrame:CGRectMake(260,5,40,40)];
if(correct)
    [image setImage:[UIImage imageNamed:@"right.png"]];
else
    [image setImage:[UIImage imageNamed:@"wrong.png"]];
image.autoresizingMask;
image setBackgroundColor:[UIColor clearColor]];
[cell addSubview:jimage];
[jobStatus release];
请注意,我只能使用我的图像,不能使用桌子的附件类型

而且我的表视图(在运行时创建)中没有固定数量的行

因此,我也不能使用类imageView


请帮助

设置
UIImageView的标记
,以便您以后可以使用

[imageView setTag:10];
然后,您可以通过调用

[[tableViewCell viewWithTag:10] setImage:[UIImage imageNamed:@"wrong.png"]];
另一种解决方案:在单元格的右侧显示图像。您可以设置表格视图单元格的附件视图

[tableViewCell setAccessoryView:imageView];
这样,您就可以使用

[(UIImageView*)tableViewCell.accessoryView setImage:...];

使用类似的方法,比如当您将单元格出列时:询问单元格的imageView,如果它不在那里,则创建它

#define kTagCellImageView 42

- (UITableViewCell *)tableView:(UITableView *)tableView_ cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    static NSString *CellIdentifier = @"EditorCell";

    UITableViewCell *cell = [tableView_ dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
    }

    UIImageView *imageView = [cell viewWithTag:kTagCellImageView];
    if (imageView == nil) {
        imageView = [[UIImageView alloc]initWithFrame:CGRectMake(260,5,40,40)];
        imageView.backgroundColor = [UIColor clearColor];
        imageView.tag = kTagCellImageView;
        [cell addSubview:imageView];
    }
    if (correct)
        [imageView setImage:[UIImage imageNamed:@"right"]];
    else 
        [imageView setImage:[UIImage imageNamed:@"wrong"]];
    cell.textLabel.text = [[textLabels objectAtIndex:indexPath.section] objectAtIndex:indexPath.row];
    return cell;
}

+1--我想尝试第二个,但最后一行让我感到困惑..请再解释一下..首先我们将表视图单元格的附件视图设置为图像视图,然后我们可以通过accessoryView属性访问图像视图。因为accessoryView是一个UIView,所以我们必须将它强制转换为UIImageView*以便在没有编译器警告的情况下使用setImage:image。