【问题标题】:RLMCollectionChange indexes of modifications bad description?RLMCollectionChange 索引修改错误描述?
【发布时间】:2017-10-18 08:54:41
【问题描述】:

根据-[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] 返回的。第二个没有访问它的属性...

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

【问题讨论】:

    标签: ios objective-c uitableview realm


    【解决方案1】:

    表视图需要一个新索引。因为在beginUpdatesendUpdates之间做是为了让table view的状态跟随改变的模型。

    此外,新旧都与modifications 无关。 modifications 是对象的位置没有变化,只是属性发生了变化。如果一个属性改变了它对对象的位置,它将被视为“移动”而不是修改。因此,它被转换为insertiondeletion,而不是modification

    【讨论】:

    • 因此,例如,如果在更新之前我们有 5 个项目,并且我们得到了删除前 4 个项目并更改最后一个项目的 collectionChange,我们将在修改中拥有索引 0?现在collectionChange说索引为4的项目被修改了......
    猜你喜欢
    • 1970-01-01
    • 2014-04-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-02-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多