错误无法使类型UICollectionElementKindCell的视图出列 [英] Error could not dequeue a view of kind UICollectionElementKindCell

查看:2070
本文介绍了错误无法使类型UICollectionElementKindCell的视图出列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

首先尝试使用集合视图并遇到此错误:

Taking first plunge with collection views and am running into this error:


由于未捕获的异常'NSInternalInconsistencyException'而终止应用,原因: '无法使类型的视图出列:具有标识符Cell的UICollectionElementKindCell - 必须为标识符注册nib或类或在故事板中连接原型单元'

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

代码非常简单,如下所示。我不能为我的生活弄清楚我错过了什么。

The code is very simple, as shown below. I can't for the life of me figure out what it is that I'm missing.

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
UICollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"Cell" forIndexPath:indexPath];
cell.backgroundColor = [UIColor whiteColor]; 
return cell;
}

集合视图控制器是使用nib和委托&创建的。数据源都设置为文件的所有者。

The collection view controller was created using a nib and the delegates & datasources are both set to file's owner.

View Controller的头文件也非常基本。

View Controller's header file is also really basic.

@interface NewMobialViewController_3 : UICollectionViewController <UICollectionViewDataSource, UICollectionViewDelegateFlowLayout>
@end


推荐答案

来自 UICollectionView文档用于出列方法:


重要:您必须使用registerClass注册类或nib文件:forCellWithReuseIdentifier:或registerNib:forCellWithReuseIdentifier:调用此方法之前的方法。

Important: You must register a class or nib file using the registerClass:forCellWithReuseIdentifier: or registerNib:forCellWithReuseIdentifier: method before calling this method.

这篇关于错误无法使类型UICollectionElementKindCell的视图出列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆