I'm setting up a project with a UICollectionView that displays an image with a label. I created the ViewController and the CellViewController, just like its supposed to.
In the CellViewController the code is the following:
class CellController: UICollectionViewCell {
@IBOutlet weak var image: UIImageView!
@IBOutlet weak var label: UILabel!
}
But in the ViewController when I'm setting up the image it gives me the error. Here's the code:
func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {
let cell: UICollectionViewCell = collection.dequeueReusableCellWithReuseIdentifier("Cell", forIndexPath: indexPath) as! CellController
cell.image.image = UIImage(named: "star")
return cell
}
And the weirdest thing is, I have a project downloaded from GitHub that is essentially the same as mine, and it works fine.
Thanks in advance!
Your problem is the
:UICollectionViewCell. Although you cast your cell asCellControllerthis makes the typeUICollectionViewCell, which does not have an image property. Removing this or replacing it withCellControllerwill fix your problem.I would also consider renaming your image view to
imageView. There's something about the linecell.image.imagethat doesn't look right!