美文网首页
Exception集合

Exception集合

作者: 喵喵粉 | 来源:发表于2020-02-26 14:52 被阅读0次
    1. 刷新collectionviewcrash

    reason: 'UICollectionView received layout attributes for a cell with an index path that does not exist: <NSIndexPath: 0xc000000000200016> {length = 2, path = 0 - 1}'

    解决:
    reloadData之后将当前的布局设置失效invalidateLayout,则collectionView会重新刷新布局,否则就会沿用旧的布局导致获取不到数据,导致崩溃。

    collectionView.reloadData()
    collectionView.collectionViewLayout.invalidateLayout()
    
    1. 10.*系统下collectionview crash

    *** Assertion failure in -[_UIFlowLayoutSection computeLayoutInRect:forSection:invalidating:invalidationContext:], /BuildRoot/Library/Caches/com.apple.xbs/Sources/UIKit_Sim/UIKit-3600.7.47/UIFlowLayoutSupport.m:823
    *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'UICollectionViewFlowLayout internal error'
    *** First throw call stack:
    (
    0 CoreFoundation 0x0000000106c11b0b __exceptionPreprocess + 171
    1 libobjc.A.dylib 0x0000000106676141 objc_exception_throw + 48
    2 CoreFoundation 0x0000000106c15cf2 +[NSException raise:format:arguments:] + 98
    3 Foundation 0x0000000103535536 -[NSAssertionHandler handleFailureInMethod:object:file:lineNumber:description:] + 193
    4 UIKit 0x000000010508ef1b -[_UIFlowLayoutSection computeLayoutInRect:forSection:invalidating:invalidationContext:] + 13308
    5 UIKit 0x0000000105024f11 __76-[UICollectionViewFlowLayout _updateItemsLayoutForRect:allowsPartialUpdate:]_block_invoke + 533
    6 CoreFoundation 0x0000000106ba2652 __53-[__NSArrayM enumerateObjectsWithOptions:usingBlock:]_block_invoke + 114

    解决:
    在布局生效前调用invalidateLayout

    override func viewWillLayoutSubviews() {
        super.viewWillLayoutSubviews()
        collectionView.collectionViewLayout.invalidateLayout()
    }
    

    相关文章

      网友评论

          本文标题:Exception集合

          本文链接:https://www.haomeiwen.com/subject/qssvchtx.html