Reputation:
I have faced this error:
Thread 1: signal SIGABRT error I got in 3rd override function in cell declaration
Could not cast value of type 'UICollectionViewCell' (0x10d27aa18) to 'collection.viewcell' (0x10a431130).
extension PhotoCollectionViewController {
override func numberOfSections(in collectionView: UICollectionView) -> Int {
return searches.count
}
//2
override func collectionView(_ collectionView: UICollectionView,
numberOfItemsInSection section: Int) -> Int {
return searches[section].searchResults.count
}
//3
override func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: reuseIdentifier, for: indexPath) as! viewcell
//2
let flickrPhoto = photoForIndexPath(indexPath: indexPath)
print(flickrPhoto)
cell.backgroundColor = UIColor.white
//3
//cell.imageview.image = flickrPhoto.thumbnail
return cell
}
}
Upvotes: 0
Views: 60
Reputation: 7669
Change the viewcell to UICollectionViewCell
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: reuseIdentifier, for: indexPath) as! UICollectionViewCell
If you want to use custom cell the first register and use. Make sure registerClass and dequeueReusableCell are the same class to solve the problem.
self.registerClass(viewcell.self, forCellWithReuseIdentifier: reuseIdentifier)
let cell = collectionView.dequeueReusableCellWithReuseIdentifier(reuseIdentifier, forIndexPath: indexPath) as! viewcell
This will help.
Upvotes: 1