错误:UICollectionView收到具有Swift中不存在的索引路径的单元格的布局属性 [英] Error: UICollectionView received layout attributes for a cell with an index path that does not exist in Swift

查看:76
本文介绍了错误:UICollectionView收到具有Swift中不存在的索引路径的单元格的布局属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我" https://www.raywenderlich.com/392-uicollectionview-custom-layout-tutorial-pinterest "创建一个自定义UICollectionView.(以调整单元格高度)

I "https://www.raywenderlich.com/392-uicollectionview-custom-layout-tutorial-pinterest" To create a Custom UICollectionView. (To adjust cell height)

如果我向上滚动,该单元将继续添加,并从上到下滚动以刷新.

If I scroll up, the cell will continue to be added, and scroll from top to bottom to refresh.

运行应用程序并最初增长Cells时没有问题.但是,刷新或重新排序单元格数量时始终会出现错误.

There is no problem when you run your app and initially grow Cells. However, there is always an error when refreshing or reordering the number of cells.

错误:

***-[UICollectionViewData validateLayoutInRect:],/BuildRoot/Library/Caches/com.apple.xbs/Sources/UIKitCore/UIKit-3698.93.8/UICollectionViewData.m:447

*** Assertion failure in -[UICollectionViewData validateLayoutInRect:], /BuildRoot/Library/Caches/com.apple.xbs/Sources/UIKitCore/UIKit-3698.93.8/UICollectionViewData.m:447

***由于未捕获的异常'NSInternalInconsistencyException'而终止应用程序,原因:'UICollectionView接收到具有不存在索引路径的单元格的布局属性:

*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'UICollectionView received layout attributes for a cell with an index path that does not exist :

因此," iOS 10错误:UICollectionView收到索引路径不存在的单元格的布局属性"并尝试解决该错误.

Therefore, "iOS 10 bug: UICollectionView received layout attributes for a cell with an index path that does not exist" And tried to solve the error.

在下面的行

self.artCollectionView.reloadData () 

我尝试添加

self.artCollectionView.collectionViewLayout.invalidateLayout () 

但未解决.

而且,我不知道在哪里运行

Also, I do not know where to run

cache.removeAll ()

在prepare()部分中的

.(PinterestLayout.swift中有一个prepare()函数)

in the prepare () section. (There is a prepare () function in PinterestLayout.swift)

解决错误的正确方法是什么?

What is the correct way to resolve the error?

推荐答案

PinterestLayout.swift 中应该有 prepare 函数,因为它是唯一使用的布局用于自定义 collectionView .

There is prepare function in PinterestLayout.swift as it should be because it is the only layout used for customizing the collectionView.

在第76行的 PinterestLayout.swift 中文件.

尝试

override public func prepare() {
    cache.removeAll()
    if cache.isEmpty {
       .....
    }
}

这篇关于错误:UICollectionView收到具有Swift中不存在的索引路径的单元格的布局属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆