问题描述
'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
网友评论