0

I have a collection view in a storyboard with 4 collection view cell prototypes with the following identifiers: "Cell", "NoAlbumSelectedCell", "NoPhotosCell" and "NoVideosCell".

This is the code I'm using to load the cells:

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView
              cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
if (self.noAlbumSelected) {
    return [collectionView dequeueReusableCellWithReuseIdentifier:@"NoAlbumSelectedCell" forIndexPath:indexPath];
}

if ([self.medias count] == 0) {
    if ([self.listType isEqualToString:@"photo"]) {
        UICollectionViewCell *noPhotosCell = [collectionView dequeueReusableCellWithReuseIdentifier:@"NoPhotosCell" forIndexPath:indexPath];
        return noPhotosCell;
    } else {
        UICollectionViewCell *noVideosCell = [collectionView dequeueReusableCellWithReuseIdentifier:@"NoVideosCell" forIndexPath:indexPath];
        return noVideosCell;
    }
}

MediaCollectionViewCell *cell = (MediaCollectionViewCell *)[collectionView dequeueReusableCellWithReuseIdentifier:@"Cell" forIndexPath:indexPath];

[self configureCell:cell forItemAtIndexPath:indexPath];

return cell;
}

When I try to display the "NoPhotosCell" cell, I get the following error:

*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'could not dequeue a view of kind: UICollectionElementKindCell with identifier NoPhotosCell - must register a nib or a class for the identifier or connect a prototype cell in a storyboard'

I tried to do a clean and rebuild.

4

2 回答 2

1

您是否在 viewController 的 viewDidLoad 末尾添加了以下几行?

[self.collectionView registerClass:[MediaCollectionViewCell class] forCellWithReuseIdentifier:@"Cell"];
[self.collectionView registerClass:[UICollectionViewCell class] forCellWithReuseIdentifier:@"NoAlbumSelectedCell"];
[self.collectionView registerClass:[UICollectionViewCell class] forCellWithReuseIdentifier:@"NoPhotosCell"];
[self.collectionView registerClass:[UICollectionViewCell class] forCellWithReuseIdentifier:@"NoVideosCell"];

如果你有 UICollectionViewCell 的子类,那么你应该[YourUICollectionViewSubClass class]结合以上几行使用。

于 2014-06-20T10:15:13.917 回答
0

您在 viewdidload 中编写了以下代码

// Do any additional setup after loading the view from its nib.
    [self.collectionView registerClass:[CollectionViewImageCell class] forCellWithReuseIdentifier:@"Cell"];
于 2014-06-20T11:55:57.923 回答