問題描述
'NSInternalInconsistencyException', reason: 'negative sizes are not supported in the flow layout'
問題分析
查閱堆棧發(fā)現(xiàn)是與UICollectionView的布局layout相關(guān)缓呛,經(jīng)過測試發(fā)現(xiàn)是sizeForItemAtIndexPath
方法返回了非正數(shù)導(dǎo)致的蜒滩。
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(非負數(shù),非負數(shù));
}
鏈接
https://github.com/Mr-yuwei/iOS-Notes/blob/master/errorCode/CommonError.md