天天看点

关于collectionview的初始化

Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'UICollectionView must be initialized with a non-nil layout parameter'

-(void)_initPhotoShowView{

    UICollectionViewFlowLayout *flowLayout = [[UICollectionViewFlowLayout alloc] init];
    [flowLayout setItemSize:CGSizeMake(kCellItemWidth, kCellItemWidth)];//cell item的大小
    flowLayout.minimumLineSpacing = kminimumLineSpacing;//每行的间距)
    flowLayout.minimumInteritemSpacing = kMinimumInteritemSpacing;//每行内部cell item的间距
    [flowLayout setScrollDirection:UICollectionViewScrollDirectionVertical];//Scrolling direction(滚动方向)
   
    photoCollectionView = [[UICollectionView alloc] initWithFrame:CGRectMake(0, 64,kScreenWidth, kScreenHeight-64) collectionViewLayout:flowLayout];//一定要collectionViewLayout:flowLayout   (Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'UICollectionView must be initialized with a non-nil layout parameter’)
    [photoCollectionView registerClass:[PhotoCollectionViewCell class] forCellWithReuseIdentifier:@"photoShowCell"];//进行Cell类的注册
    photoCollectionView.delegate = self;
    photoCollectionView.dataSource = self;
    photoCollectionView.contentInset = UIEdgeInsetsMake(2, 1, 1, 1);
   
    [self.view addSubview:photoCollectionView];


}