ios - 作为 XIB 的 TableViewCell 中的 Collection View

标签 ios objective-c iphone xcode uistoryboard

所以我在tableViewCell 中有一个collectionView。

当 tableViewCell 在我的 Storyboard中时,一切正常。

我决定将 tableViewCell 移动到它自己的 XIB,因为 Storyboard 滞后。现在它给出了错误->

**** 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'****



在 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 Collection View -->
        TagsCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"TagCellReview" forIndexPath:indexPath];
        cell.tagLabel.text = [reviewSection.serviceTags objectAtIndex:indexPath.row];
        return cell;

知道为什么会这样吗?可能的解决方案?

最佳答案

如果单元格在 Storyboard 中,我认为您需要为 Collection View 单元格注册类和/或如果您在 xib 中设计单元格,则需要为 Collection View 单元格注册 nib。

//For Storyboard

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

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

关于ios - 作为 XIB 的 TableViewCell 中的 Collection View ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37203906/

相关文章:

ios - Xcode 6 启动失败 : timed out trying to launch app on iPad

ios - 具有备用文件名的 UIActivityViewController?

iphone - 判断ivar是否为BOOL

ios - Swift 自定义键盘 - 在键盘长按时显示额外的字母弹出窗口?

objective-c - XCode - 将测试与源链接,而不将所有源文件添加到测试任务

ios - 用于 iOS 应用程序的最佳数据库

iphone - 如何增加iPhone表格 View 中单元格的高度?

iphone - UISearchDisplayController 隐藏阴影

ios - 如何检查文档文件夹中是否存在文件?

iphone - Objective-C——子类中委托(delegate)的子类