Why can't I discard the UICollectionViewCell for a subclass?

I create a collection, and made my own customCell. I indicated this in the identity inspector, and as far as I can tell, I did everything right.

The code

import UIKit

class SubjectCollectionViewCell: UICollectionViewCell {
    @IBOutlet weak var imageView: UIImageView!
    @IBOutlet weak var label: UILabel!
}

and in my collection ViewController

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

    let cell = collectionView.dequeueReusableCellWithReuseIdentifier(reuseIdentifier, forIndexPath: indexPath) as! SubjectCollectionViewCell

    return cell
}

The following error message appears

"Cannot pass a value of type 'UICollectionViewCell' (0x110460820) to 'project.SubjectCollectionViewCell' (0x10eceeda0). (Lldb)"

+4
source share
3 answers

reference: Failed to distinguish value of type 'UICollectionViewCell'

if you see this in your ViewController collection, delete it. self.collectionView!.registerClass(UICollectionViewCell.self, forCellWithReuseIdentifier: reuseIdentifier)

+11

, viewDidLoad() Xcode ​​, :

self.collectionView!.register(UICollectionViewCell.self, forCellWithReuseIdentifier: reuseIdentifier) ​​

, , Xcode viewDidLoad()

+1

Have you written reuseIdentifier so that it creates an object of the desired class?

-2
source

All Articles