Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

appname.ViewsVC collectionView:cellForItemAtIndexPath:]: unrecognized selector sent to instance

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.

like image 734
user6520705 Avatar asked Dec 11 '16 00:12

user6520705


1 Answers

I realized that I was missing UICollectionViewDataSource and UICollectionViewDelegate at the top of the View controller

class ViewsVC: UIViewController, UICollectionViewDataSource, UICollectionViewDelegate {

like image 154
user6520705 Avatar answered Oct 21 '22 03:10

user6520705