RLMCollectionChange索引修改不好描述?

时间:2017-10-18 08:54:41

标签: ios objective-c uitableview realm

根据-[RLMCollectionChange modifications]的文档,它返回The indices in the new version of the collection which were modified.。但是示例如下所示:

 [tv beginUpdates];
 [tv deleteRowsAtIndexPaths:[changes deletionsInSection:0] withRowAnimation:UITableViewRowAnimationAutomatic];
 [tv insertRowsAtIndexPaths:[changes insertionsInSection:0] withRowAnimation:UITableViewRowAnimationAutomatic];
 [tv reloadRowsAtIndexPaths:[changes modificationsInSection:0] withRowAnimation:UITableViewRowAnimationAutomatic];
 [tv endUpdates];

UITableView需要旧集合中的索引。这是不好的描述吗?

另一个问题是如何在新集合中获取索引?

调试器显示RLMCollectionChange包含_indices.modifications_indices.modifications_new。看起来第一个是-[RLMCollectionChange modifications]返回的内容。第二个没有财产来访问它......

当然你可以计算出来。这就是我们现在必须解决这个问题的方法。

1 个答案:

答案 0 :(得分:0)

表视图需要一个新索引。因为在beginUpdatesendUpdates之间进行操作是为了使表视图的状态遵循更改的模型。

此外,新的和旧的都与modifications无关。 modifications是对象的位置不会改变,只有属性会改变。如果属性将其位置更改为对象,则将其视为"移动"而不是修改。因此,它会转换为insertiondeletion,而不是modification