I am getting this error, trying to use a UICollectionView in Swift:
NSInternalInconsistencyException', reason: 'attempt to register a cell class which is not a subclass of UICollectionViewCell ((null))
But I think I am registering the cell:
ViewDidLoad:
override func viewDidLoad()
{
super.viewDidLoad()
self.collectionView.registerClass(NSClassFromString("CollectionCell"),forCellWithReuseIdentifier:"CELL")
}
cellForItemAtIndexPath:
func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath:NSIndexPath)->UICollectionViewCell
{
var cell = collectionView.dequeueReusableCellWithReuseIdentifier("CELL", forIndexPath: indexPath) as CollectionCell
cell.titleLabel.text="cellText"
return cell
}
and the cell class:
class CollectionCell: UICollectionViewCell
{
@IBOutlet var titleLabel : UILabel
init(coder aDecoder: NSCoder!)
{
super.init(coder: aDecoder)
}
}
Any help appreciated
You need to pass your sub-class of UICollectionViewCell, in the Swift style, to registerClass:
self.collectionView.registerClass(CollectionCell.self, forCellWithReuseIdentifier:"CELL")
If your are not using any custom class just use in ViewDidLoad
myCollectionView!.registerClass(UICollectionViewCell.self, forCellWithReuseIdentifier: "Cell")
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With