9

有时当我在 UICollectionView 未准备好时调用此代码(在调用后立即collectionView.reloadData()),它会使应用程序崩溃

        let sectionHeaderAttributes: UICollectionViewLayoutAttributes = self.collectionView.layoutAttributesForSupplementaryElement(ofKind: UICollectionElementKindSectionHeader, at: indexPath)!;

由于未捕获的异常“NSInternalInconsistencyException”而终止应用程序,原因:“-layoutAttributesForSupplementaryElementOfKind 没有 UICollectionViewLayoutAttributes 实例:路径 {length = 2, path = 0 - 0} 处的 UICollectionElementKindSectionHeader”

在调用代码之前,如何检查 UICollectionView 是否“就绪”?我们如何防范以防止崩溃发生?

4

0 回答 0