Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/110.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios layoutAttributesForSupplementaryViewOfKind:atIndexPath:传入的索引XPath不正确_Ios_Objective C_Animation_Uicollectionview_Uicollectionviewlayout - Fatal编程技术网

Ios layoutAttributesForSupplementaryViewOfKind:atIndexPath:传入的索引XPath不正确

Ios layoutAttributesForSupplementaryViewOfKind:atIndexPath:传入的索引XPath不正确,ios,objective-c,animation,uicollectionview,uicollectionviewlayout,Ios,Objective C,Animation,Uicollectionview,Uicollectionviewlayout,我有一个自定义的UICollectionViewLayout,它使用补充视图在每页底部放置页脚 在我开始在页面底部插入单元格之前,这似乎一直运行良好 由于补充视图必须链接到UICollectionView中的NSIndexPath,因此在我的prepare layout方法中,我检测到页面上的最后一个单元格,然后将补充视图的LayoutAttribute存储到页面上的最后一个indexPath 这是插入新单元格之前的集合视图布局: |- Page 1 |-- [0, 0]

我有一个自定义的
UICollectionViewLayout
,它使用补充视图在每页底部放置页脚

在我开始在页面底部插入单元格之前,这似乎一直运行良好

由于补充视图必须链接到UICollectionView中的NSIndexPath,因此在我的prepare layout方法中,我检测到页面上的最后一个单元格,然后将补充视图的LayoutAttribute存储到页面上的最后一个indexPath

这是插入新单元格之前的集合视图布局:

    |- Page 1
    |-- [0, 0]
    |-- [0, 1]
    |-- [0, 2]
    |- Footer (indexPath [0, 2])
    |- Page 2
    |-- [1, 0]
    |-- [1, 1]
    |- Footer (indexPath [1, 1])
正如预期的那样,我的prepareLayout方法为InExpath
[0,2]
[1,1]
创建并存储
UICollectionViewLayoutAttribute

layouttributesforSupplementalViewofKind:atIndexPath:
方法也被调用两次,返回IndExpath的正确属性(
[0,2]
[1,1]

现在的问题是,当我在索引
[1,2]
处插入一个新单元格时,
prepareLayout
方法会正确地重新计算布局,并将第二个页脚的indexPath更改为您所期望的
[1,2]

但是,当再次调用
layouttributesforSupplementaryViewOfKind:atIndexPath:
以更新接口时,其
indexPath
属性仍然返回
[1,1]
。然后在方法上返回nil,因为它不存在并导致崩溃(显然)

为什么
layouttributesforSupplementaryViewofKind:atIndexPath:
仍然返回不正确(旧)的indexPath?我已经检查了布局是否无效,以及存储LayoutAttribute的footerAttributes字典是否具有正确的(新的)indexPath,因此从我所读的内容来看,这应该可以正常工作

同样重要的是要注意,这只发生在动画插入发生时。。。仅仅调用
reloadData
不会崩溃

此外,我无法将补充视图链接到单个节,因为我的自定义布局设计为对collectionView进行分页,并且节可以溢出到不同的页面上,这意味着每个节都有多个补充视图

以下是我的布局的.m文件的要点:

或者您可以在此处找到回购协议:

我的另一个解决方案是将补充视图分配给自定义的
nsindepath
,其中
indepath.row
值将决定补充视图位于哪个页面上,但我不确定这是否是处理此问题的合适方法,因此我认为我会在开始之前征求建议

任何帮助都会很好


谢谢。

我也遇到了同样的问题。您找到解决方案了吗?将补充视图分配给自定义NSIndexPath的替代解决方案在这里对mesame有效,这完全是同一个问题。的文档中说:“由您决定如何使用indexPath参数来标识给定的补充视图。”因此,您的替代解决方案似乎是可以接受的处理方法。