I am building a collection view and am getting the following error.
Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[appname.ViewsVC collectionView:cellForItemAtIndexPath:]: unrecognized selector sent to instance
Here is the code where i custom cell
// cell configuration
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell{
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "ViewsCell", for: indexPath) as! ViewsCell
cell.fullnameLbl.text = self.viewsArray[(indexPath as NSIndexPath).row].capitalizeEachWord
// pic setup
avaArray[indexPath.row].getDataInBackground { (data:Data?, error:Error?) in
if error == nil {
cell.avaImg.image = UIImage(data: data!)
}
}
return cell
}
I created the collection view and the cell in storyboard and have given them the proper identifiers. I also connected the UIimageView and the label to the cell class.
Any ideas what could be wrong.
I realized that I was missing UICollectionViewDataSource and UICollectionViewDelegate at the top of the View controller
class ViewsVC: UIViewController, UICollectionViewDataSource, UICollectionViewDelegate {
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With