所以我在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/