I have a custom UITabvleViewCell that has a UIImageView in it. I can set the image fine when the cell is setup in cellForRowAtIndexPath (though I don’t) however under certain conditions I need to change the image and have been doing so with the following code.
-(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;
}
}
}
This works and the image gets updated however when you scroll the cell off the screen and back onto the screen the image is reset!
I need it to *stick with the new image.
This is not recommended as you are not gaining the benefit of the dequeue mechanism for unused cells. Consider doing this when you create the cell, or create a mechanism that knows which cells this should be done to.