我有一个自定义的 UITabvleViewCell,其中有一个 UIImageView。当在 cellForRowAtIndexPath 中设置单元格时,我可以很好地设置图像(尽管我没有),但是在某些条件下,我需要更改图像,并且已经使用以下代码执行此操作。
-(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;
}
}
}
这有效并且图像会更新,但是当您将单元格从屏幕上滚动并返回到屏幕上时,图像会重置!
我需要它*坚持新图像。
最佳答案
不建议这样做,因为您无法从未使用的单元的出队机制中获益。考虑在创建单元时执行此操作,或者创建一个机制来知道应该对哪些单元执行此操作。
关于ios - 在自定义 UITableviewCell 中设置图像不会*粘*,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11180898/