collectionView的itemSize为非正数导致的闪退问题

问题描述

'NSInternalInconsistencyException', reason: 'negative sizes are not supported in the flow layout'

问题分析

查阅堆栈发现是与UICollectionView的布局layout相关,经过测试发现是sizeForItemAtIndexPath方法返回了非正数导致的。

CoreFoundation  __CFBundleDlfcnGetSymbolByNameWithSearch + 136
1 libobjc.A.dylib   objc_exception_throw + 60
2 CoreFoundation    -[NSInvocation _initWithMethodSignature:frame:buffer:size:] + 212
3 Foundation    +[NSDecimalNumber decimalNumberWithDecimal:] + 52
4 UIKitCore -[UICollectionViewTransitionLayout layoutAttributesForSupplementaryViewOfKind:atIndexPath:] + 204
5 UIKitCore -[UICollectionViewUpdate _computeItemUpdates] + 1328
6 UIKitCore -[UICollectionViewLayout convertRect:fromLayout:] + 260
7 UIKitCore -[UICollectionViewFlowLayout prepareLayout] (BaseCollectionViewFlowLayout.m:35)
8 UIKitCore -[UICollectionViewFlowLayout _invalidateButKeepDelegateInfo] + 80
9 UIKitCore -[UICollectionViewFlowLayout _didPerformUpdateVisibleCellsPass] + 640
10 UIKitCore    -[UICollectionView _endItemAnimationsWithInvalidationContext:tentativelyForReordering:animator:] + 3720
问题解决
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath{
    return CGSizeMake(非负数,非负数);
}
链接

https://github.com/Mr-yuwei/iOS-Notes/blob/master/errorCode/CommonError.md

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容