
我做了一些日志记录,在第一个实例中是什么跟随,是当我们从一些数据开始时,或者当我们将一个项目插入到集合视图中时,集合视图被计算的正确和逻辑的方式.
第二组日志是当我删除一个对象从我的数据源deleteItemsAtIndexPaths:.
我的layoutAttributesForElementsInRect:看起来像这样:
- (NSArray *)layoutAttributesForElementsInRect:(CGRect)rect{ NSMutableArray* attributes = [NSMutableArray array]; for (NSInteger i = 0 ; i < [self.myData count]; i++) { NSIndexPath *indexPath = [NSIndexPath indexPathForItem:i inSection:0]; NSLog(@"%@ indexPath.row:%d",NsstringFromSelector(_cmd),indexPath.row); UICollectionVIEwLayoutAttributes *att = [self layoutAttributesForItemAtIndexPath:indexPath]; [attributes addobject:att]; UICollectionVIEwLayoutAttributes *att_supp = [self layoutAttributesForSupplementaryVIEwOfKind:@"one_kind" atIndexPath:indexPath]; [attributes addobject:att_supp]; UICollectionVIEwLayoutAttributes *linesAttr = [self layoutAttributesForSupplementaryVIEwOfKind:@"another_kind" atIndexPath:indexPath]; [attributes addobject:linesAttr]; } return attributes;} 初始日志(正确和逻辑):
MyApp[18546:70b] layoutAttributesForElementsInRect: indexPath.row:0MyApp[18546:70b] layoutAttributesForSupplementaryVIEwOfKind:atIndexPath: indexPath.row:0MyApp[18546:70b] layoutAttributesForSupplementaryVIEwOfKind:atIndexPath: indexPath.row:0MyApp[18546:70b] layoutAttributesForElementsInRect: indexPath.row:1MyApp[18546:70b] layoutAttributesForSupplementaryVIEwOfKind:atIndexPath: indexPath.row:1MyApp[18546:70b] layoutAttributesForSupplementaryVIEwOfKind:atIndexPath: indexPath.row:1MyApp[18546:70b] layoutAttributesForElementsInRect: indexPath.row:2MyApp[18546:70b] layoutAttributesForSupplementaryVIEwOfKind:atIndexPath: indexPath.row:2MyApp[18546:70b] layoutAttributesForSupplementaryVIEwOfKind:atIndexPath: indexPath.row:2
删除项目后:
MyApp[18633:70b] layoutAttributesForElementsInRect: indexPath.row:0MyApp[18633:70b] layoutAttributesForSupplementaryVIEwOfKind:atIndexPath: indexPath.row:0MyApp[18633:70b] layoutAttributesForSupplementaryVIEwOfKind:atIndexPath: indexPath.row:0MyApp[18633:70b] layoutAttributesForElementsInRect: indexPath.row:1MyApp[18633:70b] layoutAttributesForSupplementaryVIEwOfKind:atIndexPath: indexPath.row:1MyApp[18633:70b] layoutAttributesForSupplementaryVIEwOfKind:atIndexPath: indexPath.row:1MyApp[18633:70b] layoutAttributesForSupplementaryVIEwOfKind:atIndexPath: indexPath.row:2
正如你可以看到layoutAttributesForSupplementaryVIEwOfKind:atIndexPath:被调用,但是绕过layoutAttributesForElementsInRect:
有谁知道会发生什么问题?
解决方法 我有同样的问题.我的布局为集合视图中的每个项目使用一个补充视图.我用几个步骤解决了这个问题.首先,在 – prepareForCollectionVIEwUpdates :,我列举更新,并确定哪些项目正在消失.我缓存该组索引路径.
然后布局将调用 – indexPathsToDeleteForSupplementaryVIEwOfKind :.我刚从上面返回缓存的结果.
最后,在 – finalizeCollectionVIEwUpdates中,我清除缓存.我想这个步骤是可选的.
我也这样做了 – indexPathsToInsertForSupplementaryVIEwOfKind:为了一致性,尽管它没有它工作正常.
总结以上是内存溢出为你收集整理的ios – 补充视图不被删除全部内容,希望文章能够帮你解决ios – 补充视图不被删除所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)