【发布时间】:2015-10-13 10:28:33
【问题描述】:
我在尝试加载 UICollectionView 时收到此错误消息。
2015-07-23 16:16:09.754 XXXXX[24780:465607] 由于以下原因而终止应用程序 未捕获的异常“NSInternalInconsistencyException”,原因:“可能 不出队一种视图: UICollectionElementKindCell 与 标识符 CollectionViewCell - 必须为 标识符或连接故事板中的原型单元'
第一次抛出调用栈:
我的代码
@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
}
我已经在故事板检查器中声明了CollectionViewCell,但错误消息仍然出现。
【问题讨论】:
-
我猜你正在单独创建你的 Cell nib,而不是在你的
UICollectionView中。如果是,则需要先将 nib 文件注册到UICollectionView。使用 UINib *cellNib = [UINib nibWithNibName:@"CollectionViewCell" bundle:nil]; [self.collectionView registerNib:cellNib forCellWithReuseIdentifier:@"CollectionViewCell"];
标签: ios swift uicollectionview uicollectionviewcell