【发布时间】:2015-06-19 07:50:12
【问题描述】:
我正在像这样注册单元格:
collectionView!.registerNib(UINib(nibName: "ItemCell", bundle: nil), forCellWithReuseIdentifier: "ItemCellIdentifier")
并像这样访问它:
let cell = collectionView.dequeueReusableCellWithReuseIdentifier("ItemCellIdentifier", forIndexPath: indexPath) as! ItemCell
ItemCell 是 UICollectionViewCell 的子类:
class ItemCell: UICollectionViewCell {
@IBOutlet weak var itemImage: UIImageView!
@IBOutlet weak var itemImageDescription: UILabel!
//creation from nib requires this method to be overridden
override func awakeFromNib() {
super.awakeFromNib()
// Initialization code
}
required init(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
}
}
最后我有一个带有类 ItemCell 的 UICollectionViewCell 的 xib。
我不断收到错误:
-[UICollectionView 中的断言失败 _dequeueReusableViewOfKind:withIdentifier:forIndexPath:viewCategory:], /SourceCache/UIKit/UIKit-3347.44.2/UICollectionView.m:3443.
崩溃就在这一行:
let cell = collectionView.dequeueReusableCellWithReuseIdentifier("ItemCellIdentifier", forIndexPath: indexPath) as! ItemCell
编辑
collectionView!.registerNib(UINib(nibName: "ItemCell", bundle: nil), forCellWithReuseIdentifier: "ItemCellIdentifier")
被调用
override init(style: UITableViewCellStyle, reuseIdentifier: String?) {
super.init(style: style, reuseIdentifier: reuseIdentifier)
}
包含在:
class CollectionCell : UITableViewCell, UICollectionViewDataSource, UICollectionViewDelegate {
【问题讨论】: