Ios 在自定义UITableviewCell中设置图像不*粘滞*

Ios 在自定义UITableviewCell中设置图像不*粘滞*,ios,uitableview,Ios,Uitableview,我有一个自定义UIABVLeviewCell,其中包含UIImageView。当在CellForRowatineXpath中设置单元格时,我可以很好地设置图像(尽管我没有),但是在某些情况下,我需要更改图像,并且已经使用以下代码进行了更改 -(void)updateCellForUPC { AppData* theData = [self theAppData]; NSInteger cellIndex; for (cellIndex = 0; cellIndex &l

我有一个自定义UIABVLeviewCell,其中包含UIImageView。当在CellForRowatineXpath中设置单元格时,我可以很好地设置图像(尽管我没有),但是在某些情况下,我需要更改图像,并且已经使用以下代码进行了更改

-(void)updateCellForUPC
{
    AppData* theData = [self theAppData];

    NSInteger cellIndex;
    for (cellIndex = 0; cellIndex < [productArray count]; cellIndex++) {

      NSString *cellUPC = [NSString stringWithFormat:@"%@",[[productArray objectAtIndex:cellIndex] objectForKey:@"UPC"]];

        if ([cellUPC isEqualToString:theData.UPC]) {

            OrderDetailCell *activeCell = [[OrderDetailCell alloc] init];
            activeCell = (OrderDetailCell *) [orderDetailTableView cellForRowAtIndexPath:[NSIndexPath indexPathForRow:cellIndex inSection:0]];

            UIImage* image = [UIImage imageNamed:@"checkmark.png"];
            activeCell.statusImageView.image = image;
            activeCell.checked = YES;
        }
    }
}
-(无效)updateCellForUPC
{
AppData*theData=[self theAppData];
NSInteger细胞指数;
对于(cellIndex=0;cellIndex<[productArray count];cellIndex++){
NSString*cellUPC=[NSString stringWithFormat:@“%@,[[productArray objectAtIndex:cellIndex]objectForKey:@“UPC”];
if([cellUPC IsequalString:theData.UPC]){
OrderDetailCell*activeCell=[[OrderDetailCell alloc]init];
activeCell=(OrderDetailCell*)[orderDetailTableView cellForRowAtIndexPath:[NSIndexPath indexPathForRow:cellIndex片段:0]];
UIImage*image=[UIImage ImageName:@“checkmark.png”];
activeCell.statusImageView.image=图像;
activeCell.checked=是;
}
}
}
这是可行的,图像会得到更新,但是当您将单元格从屏幕上滚动到屏幕上时,图像会被重置


我需要它来保持新形象

不建议这样做,因为对于未使用的单元,您无法获得出列机制的好处。当您创建单元格时,请考虑这样做,或者创建一个知道应该做哪些单元格的机制。p> 我创建了一个NSMutableArray,并将索引添加为NSString。。我还设置了单元格的图像(如果当时正在显示)

-(void)updateCellForUPC
{
    AppData* theData = [self theAppData];

    NSInteger cellIndex;
    for (cellIndex = 0; cellIndex < [productArray count]; cellIndex++) {

      NSString *cellUPC = [NSString stringWithFormat:@"%@",[[productArray objectAtIndex:cellIndex] objectForKey:@"UPC"]];

        if ([cellUPC isEqualToString:theData.UPC]) {

            OrderDetailCell *activeCell = [[OrderDetailCell alloc] init];
            activeCell = (OrderDetailCell *) [orderDetailTableView cellForRowAtIndexPath:[NSIndexPath indexPathForRow:cellIndex inSection:0]];

            UIImage* image = [UIImage imageNamed:@"checkmark.png"];
            activeCell.statusImageView.image = image;

            NSString *index = [NSString stringWithFormat:@"%d",cellIndex];
            [selectionArray addObject:index];
        }
    }
}

我无法在创建细胞时做到这一点,它需要在事实之后。那么,您是否建议在CellForRowatineXpath中使用一些东西,根据索引+一些外部属性设置图像,然后刷新tableview?可能是需要它的单元格索引添加到的另一个数组?谢谢你的帮助,如果你好奇的话,我有下面的答案。
NSString *index = [NSString stringWithFormat:@"%d",indexPath.row];

if ([selectionArray containsObject:index]) {
    UIImage* image = [UIImage imageNamed:@"checkmark.png"];
    cell.statusImageView.image = image;
}