相关疑难解决方法(0)

Swift - 无法出现类型的视图:带标识符的UICollectionElementKindCell

尝试加载UICollectionView时收到此错误消息.

2015-07-23 16:16:09.754 XXXXX [24780:465607]由于未捕获的异常'NSInternalInconsistencyException'而终止应用程序,原因:'无法使类型的视图出列:具有标识符CollectionViewCell的UICollectionElementKindCell - 必须注册一个nib或类标识符或连接故事板中的原型单元格'

第一次抛出调用堆栈:

我的代码

@IBOutlet var collectionView: UICollectionView!

func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {

        let cell = collectionView.dequeueReusableCellWithReuseIdentifier("CollectionViewCell", forIndexPath: indexPath) as! CollectionViewCell

        cell.backgroundColor = UIColor.blackColor()
        cell.textLabel?.text = "\(indexPath.section):\(indexPath.row)"
        cell.imageView?.image = UIImage(named: "category")

        return cell

    }
Run Code Online (Sandbox Code Playgroud)

我已CollectionViewCell在故事板检查器中声明但仍出现错误消息.

在此输入图像描述

ios uicollectionview uicollectionviewcell swift

10
推荐指数
2
解决办法
1万
查看次数