如果只允许一个对勾的时间,你可以只保留当前选择indexPath(或适当的替代指标)的属性,然后你只需要更新两排。
否则,你将不得不循环。通常情况下,我有一个configureCell:atIndexPath:
的方法,我可以在任何地方(包括cellForRowAtIndexPath
)调用与reloadVisibleCells
方法相结合:
- (void)configureCell:(UITableViewCell *)cell atIndexPath:(NSIndexPath *)indexPath
{
//cell configuration logic
}
- (void)reconfigureVisibleCells
{
for (UITableViewCell *cell in [self.tableView visibleCells]) {
NSIndexPath *indexPath = [self.tableView indexPathForCell:cell];
[self configureCell:cell atIndexPath:indexPath];
}
}
或者,如果你想拥有你可以用重装细胞的更传统的方法在begin/endUpdates
三明治内置的行动画:
- (void)reloadVisibleCells
{
[self.tableView beginUpdates];
NSMutableArray *indexPaths = [NSMutableArray array];
for (UITableViewCell *cell in [self.tableView visibleCells]) {
NSIndexPath *indexPath = [self.tableView indexPathForCell:cell];
[indexPaths addObject:indexPath];
}
[self.tableView reloadRowsAtIndexPaths:indexPaths withRowAnimation:UITableViewRowAnimationFade];
[self.tableView endUpdates];
}
+1的快速反应,因为它的工作原理,似乎是完全一样的,但是我要等待,看看是否有任何其他的解决方案。看起来很奇怪,依靠快速重新选择行,对iOS来说非常“本机”的行为(许多应用程序中的常见操作) – Raekye
一些非常常见的行为没有简单的单行解决方案:) – e1985