【问题标题】:ios NSIndexPath insertItemsAtIndexPaths in UICollectionViewUICollectionView 中的 ios NSIndexPath insertItemsAtIndexPaths
【发布时间】:2014-03-25 21:14:27
【问题描述】:

我正在使用 insertItemsAtIndexPaths,但我试图了解此函数如何影响我的索引路径的排序。

我有 1 个部分和多个项目(或行)。我正在使用 UICollectionView。

当我插入新项目时,我使用带有 [NSIndexPath indexPathForItem:0 inSection:0] 的 insertItemsAtIndexPaths。我的问题是,当我在 indexPathForItem 0 处插入时,这个 collectionview 中已经存在的索引路径是否会发生变化?换句话说,假设我循环了 indexPathForItem:0。这实际上会在 UICollectionView 的开头推送项目吗?

【问题讨论】:

    标签: ios insert uicollectionview nsindexpath


    【解决方案1】:

    根据documentation,您首先更新数据源,然后调用插入方法。因此,如果您的数据源是一个包含 3 个元素(例如 A、B、C)的数组,并且您在位置 0 处添加了一个新元素 D,那么您现在拥有 @[D、A、B、C]。然后你会调用 [self.collectionView insertItemsAtIndexPaths:@[[NSInexPath indexPathForItem:0 inSection:0]]];。

    如果布局表明这会影响屏幕上的任何项目,则 cellForItemAtIndexPath 方法将被调用受影响的行,并且数据源将返回要在其中显示的内容。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-10-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多