IOS:注册UICollectionViewCell崩溃

报错 reason: 'could not dequeue a view of kind: UICollectionElementKindCell with identifier cell - must register a nib or a class for the identifier or connect a prototype cell in a storyboard'

首先我采用的是自定义xib继承与UICollectionViewCell,注册时出现了这个错误

后来改了下注册方式

[_collectionView registerNib:[UINib nibWithNibName:@"PhotoCell" bundle:nil]
forCellWithReuseIdentifier:@"PhotoCellID"];

并且上面这条注册语句放在了设置基本信息的地方。

在cellforItemAtIndexPath里

static NSString * CellIdentifier = @"PhotoCellID";
PhotoCell * cell = [collectionView dequeueReusableCellWithReuseIdentifier:CellIdentifier forIndexPath:indexPath];

解决问题