2017-10-18 87 views
0

根據-[RLMCollectionChange modifications]的文檔,它返回The indices in the new version of the collection which were modified.。但是示例如下所示:RLMCollectionChange修改索引的修改錯誤描述?

[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]返回。第二個沒有財產訪問它...

當然,你可以計算它。這就是我們現在要解決這個問題的方法。

回答

0

表視圖需要一個新的索引。因爲beginUpdatesendUpdates之間的做法是使表視圖的狀態跟隨更改的模型。

另外,無論是新的還是舊的都與modifications有關。 modifications是對象的位置不變,只有屬性發生變化。如果一個屬性改變它的位置到對象,它將被視爲「移動」而不是修改。因此,它被轉換爲insertion和​​,而不是modification

+0

因此,例如,在更新之前,我們有5個項目,我們得到了collectionChange,刪除前4個項目,並更改最後一個,我們將在索引0中進行修改?現在collectionChange說索引4的項目被修改... –