- (NSInteger)collectionView:(UICollectionView *)view numberOfItemsInSection:(NSInteger)section {
return [cells count];
}
// 2
- (NSInteger)numberOfSectionsInCollectionView: (UICollectionView *)collectionView {
return 1;
}
// 3
- (UICollectionViewCell *)collectionView:(UICollectionView *)cv cellForItemAtIndexPath:(NSIndexPath *)indexPath {
MovieItemCell * cell = (MovieItemCell *)[cv dequeueReusableCellWithReuseIdentifier:@"MovieCell" forIndexPath:indexPath];
return cell;
}
其中3的返回,必须是dequeueReusableCellWithReuseIdentifier返回的,不能是alloc的。
否则返回错误:reason: 'the cell returned from -collectionView:cellForItemAtIndexPath: does not have a reuseIdentifier - cells must be retrieved by calling -dequeueReusableCellWithReuseIdentifier'
http://www.raywenderlich.com/zh-hans/24595/%E5%9C%A8-ios-6%E5%BC%80%E5%A7%8B-uicollectionview-part-12