Reputation: 6634
I have what appears to be successfully parsed AS3 image links to an array of UIImage named 'smImg'.
I am now trying to append each link as a UIImage to my UICollectionViewCell's imageView (where I added an IBOutlet 'imageView'.) I keep getting the error 'UICollectionViewCell' does not have a member named 'imageView'. Relevant code below.
ViewModel.swift :
func imageForItemAtIndexPath(indexPath: NSIndexPath) -> UIImage {
return smImg[indexPath.row]
}
ViewController.swift
func configureCell(cell: UICollectionViewCell, atIndexPath indexPath: NSIndexPath) {
cell.imageView!.image = viewModel.imageForItemAtIndexPath(indexPath) //Error occurs here
}
override func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCellWithReuseIdentifier("cell", forIndexPath: indexPath) as PhotoCell
configureCell(cell, atIndexPath: indexPath)
return cell
}
PhotoCell.swift
class PhotoCell: UICollectionViewCell {
@IBOutlet weak var imageView: UIImageView!
}
Can someone please help me fix this? Any help is much appreciated, I try not to ask too many questions on here but have been unable to find a solution on my own.
Upvotes: 0
Views: 679
Reputation: 2718
Your method
func configureCell(cell: UICollectionViewCell, atIndexPath indexPath: NSIndexPath) {
cell.imageView!.image = viewModel.imageForItemAtIndexPath(indexPath) //Error occurs here
}
is expecting a UICollectionViewCell, you should change it to expect a photo cell since that is what you are sending it.
func configureCell(cell: PhotoCell, atIndexPath indexPath: NSIndexPath) {
cell.imageView!.image = viewModel.imageForItemAtIndexPath(indexPath) //Error occurs here
}
You also need to make sure you're telling the collectionView to use PhotoCell as its cell type. So when you initialize the collection view you need to have a line that looks something like this
collectionView.registerClass(PhotoCell.self, forCellWithReuseIdentifier: "Reuse Identifier")
Upvotes: 1