0

没有错误日志,这就是我所看到的。

我有一个动态原型 UICollectionViewCell,并在这里加载:

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

    var cell: LeftMenuCollectionViewCell

cell = collectionView.dequeueReusableCellWithReuseIdentifier("xxx", forIndexPath: indexPath) as LeftMenuCollectionViewCell // <- at this line something goes wrong

    return cell
}

我之前正在注册课程:

self.collectionView.registerClass(UICollectionViewCell.self, forCellWithReuseIdentifier: "xxx")

现在使用 iOS 8 beta 5

在此处输入图像描述

4

3 回答 3

2

您已经注册UICollectionViewCell而不是您自己的单元格类LeftMenuCollectionViewCell。这样的铸造

UICollectionviewCell as LeftMenuCollectionViewCell 

正在破坏并导致崩溃。要修复此注册正确的类

self.collectionView.registerClass(LeftMenuCollectionViewCell.self, forCellWithReuseIdentifier: "xxx")
于 2014-08-06T12:40:31.620 回答
2

同意下面的两个解决方案,我错误地注册了 cell,但后来我发现了另一个问题,cell 的 outlets 变成了 nil。如果 UICollectionViewController 是通过 Interface Builder 创建的,则解决方案是删除整个注册。

于 2014-08-06T17:49:11.770 回答
1

您错误地注册了单元格。尝试这个:

self.collectionView.registerClass(LeftMenuCollectionViewCell.self, forCellWithReuseIdentifier: "xxx")
于 2014-08-06T12:26:43.173 回答