Kakshil Shah
Kakshil Shah

Reputation: 3816

Collection View Within TableViewCell as XIB

So I have a collectionView in a tableViewCell.

It all worked fine, when the tableViewCell was in my Storyboard.

I decided to move the tableViewCell to its own XIB because the storyboard was lagging. Now it gives the error ->

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

In CellForRowAtIndexPathTableView -->

       static NSString *CellIdentifier = @"FeedReviewCell";
       ReviewTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
            // Configure the cell...
            if (cell == nil) {
                NSArray *customCell = [[NSBundle mainBundle] loadNibNamed:@"ReviewTableViewCell" owner:self options:nil];
                cell = [customCell objectAtIndex:0];
                cell.backgroundColor=[UIColor clearColor];
                cell.selectionStyle = UITableViewCellSelectionStyleNone;
            }
        cell.tagsCollectionView.delegate = self;
        cell.tagsCollectionView.dataSource = self;

cellForItemAtIndexPath CollectionView -->

        TagsCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"TagCellReview" forIndexPath:indexPath];
        cell.tagLabel.text = [reviewSection.serviceTags objectAtIndex:indexPath.row];
        return cell;

Any idea why this happens? Possible solutions?

Upvotes: 1

Views: 980

Answers (1)

MD.
MD.

Reputation: 1167

I think you need to register class for collection view cell if the cell is in Storyboard and/or register nib for collection view cell if you designed the cell in xib.

//For Storyboard

    [cell.collectionView registerClass:[TagsCollectionViewCell class] forCellWithReuseIdentifier:@"TagsCollectionViewCell"];

// register nib for XIB
    [cell.collectionView registerNib:[UINib nibWithNibName:@"TagsCollectionViewCell" bundle:nil] forCellWithReuseIdentifier:@"TagsCollectionViewCell"];

Upvotes: 2

Related Questions