gpt4 book ai didi

ios - 在 UICollectionView 的开头插入部分

转载 作者:行者123 更新时间:2023-11-29 02:10:12 25 4
gpt4 key购买 nike

我想向 UICollectionView 添加一些部分。索引零处的 insertSections 对我不起作用。所以我的想法是在末尾插入 insertSections ,然后使用 moveSection:toSection: 将元素从末尾移动到开头。我得到了

NSInternalInconsistencyException Reason: attempt to move section 36, but there are only 36 sections before the update

我只能提供C#代码,但你也可以发布Objective-C/Swift。

this.controller.CollectionView.PerformBatchUpdatesAsync (
delegate() {
nint sectionsBefore = this.controller.CurrentNumberOfSections;
this.controller.CurrentNumberOfSections += 12;
this.controller.CollectionView.InsertSections(NSIndexSet.FromNSRange(new NSRange(sectionsBefore,12)));
for(nint i=sectionsBefore; i<=this.controller.CurrentNumberOfSections; i++){
this.controller.CollectionView.MoveSection(i,0);
}
}
);

编辑:

这是变量的输出:

sectionsBefore: 36  
CurrentNumberOfSections: 48
Range: <NSIndexSet: 0x7a77b9b0>[number of indexes: 12 (in 1 ranges), indexes: (36-47)]
36
37
38
39
40
41
42
43
44
45
46
47

最佳答案

如果您有 36 个部分,那么您的有效部分索引为 0-35,但您的循环最终将调用 MoveSection(36, 0) .你应该使用 <而不是 <= .

关于ios - 在 UICollectionView 的开头插入部分,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29371119/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com