0

I created a custom UICollectionViewCell and I tried to reference it from UICollectionView delegate method cellForItemAtIndexPath and I keep getting Cannot assign value of type 'UICollectionViewCell' to type 'GridViewCell'

Delegate Method

override func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell { let asset = self.assetsFetchResults[indexPath.item] as! PHAsset var cell = GridViewCell() //Deque an GridViewCell cell = collectionView.dequeueReusableCellWithReuseIdentifier(CellReuseIdentifier, forIndexPath: indexPath) cell.representedAssetIdentifier = asset.localIdentifier return cell } 

GridViewCell class

import UIKit class GridViewCell: UICollectionViewCell { @IBOutlet weak var imageView: UIImageView! var thumbnailImage = UIImage() var representedAssetIdentifier = NSString() override func prepareForReuse() { super.prepareForReuse() self.imageView.image = nil } //func setThumbnailImage(thumbnailImage: UIImage) { // self.imageView.image = thumbnailImage //} } 
6
  • have you assigned GridViewCell class in identity inspector of storyboard cell? Commented Nov 19, 2015 at 12:22
  • I have done that. And re-checked if I've again and again Commented Nov 19, 2015 at 12:24
  • var cell:CustomTableViewCell? = tableView.dequeueReusableCellWithIdentifier("mycell") as? CustomTableViewCell if cell == nil{ cell = CustomTableViewCell(style: UITableViewCellStyle.Subtitle, reuseIdentifier: "mycell") } Commented Nov 19, 2015 at 12:41
  • this is working in case of tableview try in same way Commented Nov 19, 2015 at 12:42
  • It's a Collectionview not a TableView Commented Nov 19, 2015 at 12:49

1 Answer 1

1

Replace

cell = collectionView.dequeueReusableCellWithReuseIdentifier(CellReuseIdentifier, forIndexPath: indexPath) 

With

cell = collectionView.dequeueReusableCellWithReuseIdentifier(CellReuseIdentifier, forIndexPath: indexPath) as! GridViewCell 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.