在其中一个视图中有一个 UITableView,它经常更新。
跟踪更改是使用“reloadRowsAtIndexPaths”以经典方式完成的
-(void)refreshCells:(NSArray *)changedCells
{
NSLog(@"refreshCells %i",[changedCells count]);
[TableView beginUpdates];
[TableView reloadRowsAtIndexPaths:changedCells withRowAnimation:UITableViewRowAnimationBottom];
[TableView endUpdates];
}
问题:如何保留用户最后选择的单元格。每次更新refreshCells后单元格位置可能会改变?
您可以保存当前选择
NSIndexPath *selectedRow = [self.tableView indexPathForSelectedRow];
在重新加载之前并再次选择它
if (selectedRow) {
[self.tableView selectRowAtIndexPath:selectedRow animated:NO scrollPosition:UITableViewScrollPositionNone];
}
重新加载后。除非您调用,否则单元格位置不会改变insertRowsAtIndexPaths:
or deleteRowsAtIndexPaths:
.
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)