2014-03-25 68 views
1

我正在使用insertItemsAtIndexPaths但我想了解這個函數如何影響我的索引路徑的排序。ios NSIndexPath insertItemsAtIndexPaths UICollectionView

我有1節和多個項目(或行)。我正在使用UICollectionView。

當我插入新項目時,我用[NSIndexPath indexPathForItem:0 inSection:0]使用insertItemsAtIndexPaths。我的問題是,當我在indexPathForItem 0處插入時,已經在此collectionview中的索引路徑是否會發生移位?換句話說,我說我looped indexPathForItem:0。這是否會在UICollectionView的開頭推動項目?

回答

1

documentation,先更新您的數據源,然後調用insert方法。因此,如果您的數據源是一個由3個元素組成的數組(例如A,B,C),並且您在位置0添加了一個新元素D,則您現在擁有@ [D,A,B,C]。然後你可以調用[self.collectionView insertItemsAtIndexPaths:@ [[NSInexPath indexPathForItem:0 inSection:0]]] ;.

如果佈局表明,這種影響在屏幕上的任何項目,則cellForItemAtIndexPath方法將被稱爲受影響的行和數據源會返回一個在他們展示。