因为UITableView
的典型重用UITableViewCell
的情况下的,你必须确保你的'-tableView:cellForRowAtIndexPath:
方法正确设置单元格的所有属性。其他陈旧的数据可以持续存在。我猜这可能是你的问题,缺乏完整的代码。
所以,这样的事情:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString* cellIdentifier = @"TheCellIdentifier";
UITableViewCell* cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier];
}
ShoppingObject* shopping = [self.myShoppingList objectAtIndex:indexPath.row];
UIImageView* accessoryView = nil;
if (shopping.isDone) {
accessoryView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"tick_btn"]];
}
cell.accessoryView = accessoryView;
return cell;
}
它获得小区,无论是从重用高速缓存或创建一个新的。然后,它会检查数据模型的状态,以查看是否购物已完成或未在该行中呈现的对象,以及购物完成后是否为您提供图像。请注意,购物没有完成,没有创建accessoryView,因此无论ShoppingObject的状态如何表示在该表格行中,该单元的accessoryView都将被正确设置。
那么,我可能会在你的-tableView:didSelectRowAtIndexPath:
中做的事情就是在表格上简单地-reloadData
,以确保一切正确更新。
PLS显示我们的代码 – manujmv
' - (空)的tableView:(UITableView的*)的tableView didSelectRowAtIndexPath方法:(NSIndexPath *)indexPath {cell = [tableView cellForRowAtIndexPath:indexPath]; 如果(cell.accessoryView ==无) { cell.accessoryView = [[ALLOC的UIImageView] initWithImage:[UIImage的imageNamed:@ “tick_btn”]]; } else { cell.accessoryView = nil; } }' – JgdGuy