I am making a collection view, and have made my own custom collectionCell. I have specified so in the identity inspector, and as far as i can tell, i have done everything right.
The code is
import UIKit
class SubjectCollectionViewCell: UICollectionViewCell {
@IBOutlet weak var imageView: UIImageView!
@IBOutlet weak var label: UILabel!
}
and in my collectionViewController
override func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCellWithReuseIdentifier(reuseIdentifier, forIndexPath: indexPath) as! SubjectCollectionViewCell
return cell
}
I get the following error message
"Could not cast value of type 'UICollectionViewCell' (0x110460820) to 'project.SubjectCollectionViewCell' (0x10eceeda0). (lldb)"
refer to : Could not cast value of type 'UICollectionViewCell'
if you see this in your collectionViewController, delete it.
self.collectionView!.registerClass(UICollectionViewCell.self, forCellWithReuseIdentifier: reuseIdentifier)
What happen is that in viewDidLoad(), Xcode automatically genere a line like this to define the cell:
self.collectionView!.register(UICollectionViewCell.self, forCellWithReuseIdentifier: reuseIdentifier)
And your are creating your own method to do this, so, you need to erase the line that was automatically generated by Xcode in the viewDidLoad()
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