首先我们先看看具体错误内容,下面的四个错误是同时报的错
-
2021-06-09 10:37:26.398808+0800 macOS[1980:65564] The behavior of the UICollectionViewFlowLayout is not defined because:
-
2021-06-09 10:37:26.398846+0800 macOS[1980:65564] the item width must be less than the width of the UICollectionView minus the section insets left and right values, minus the content insets left and right values.
-
2021-06-09 10:37:26.413082+0800 macOS[1980:65564] The relevant UICollectionViewFlowLayout instance is <NSCollectionViewFlowLayout: 0x7ff9796248b0>, and it is attached to <NSCollectionView: 0x7ff979624500>.
-
2021-06-09 10:37:26.413149+0800 macOS[1980:65564] Make a symbolic breakpoint at UICollectionViewFlowLayoutBreakForInvalidSizes to catch this in the debugger.
分析
- 首先明明是macOS项目里面的
NSCollectionView
控件,错误信息却是iOS里面的,这个是官方的原因,我们不多追究,能确定的是我的项目里面有错误的,也可以经过调整之后不再报错了 - 主要原因是
NSCollectionView
的item
、header
和footer
的大小第一次赋值之后,后面又修改了如下代码
- (NSSize)collectionView:(NSCollectionView *)collectionView layout:(NSCollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath{
return NSMakeSize(collectionView.frame.size.width, 31);
}
-
NSCollectionView
的父类NSScrollView
的滚动条是根据数据量自动显示和隐藏的,导致NSCollectionView
的宽度变宽和变窄15像素点
网友评论