获取图像时出错

时间:2018-01-18 05:27:19

标签: ios swift uicollectionview

我遇到了这个错误:

  

线程1:信号SIGABRT错误我在单元格声明中的第三个覆盖函数中得到了

     

无法将'UICollectionViewCell'(0x10d27aa18)类型的值转换为'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
    }
}

1 个答案:

答案 0 :(得分:1)

viewcell 更改为 UICollectionViewCell

 let cell = collectionView.dequeueReusableCell(withReuseIdentifier: reuseIdentifier, for: indexPath) as! UICollectionViewCell

如果要使用自定义单元格,请首先注册并使用。 确保 registerClass dequeueReusableCell 是同一个类来解决问题。

self.registerClass(viewcell.self, forCellWithReuseIdentifier: reuseIdentifier)

let cell = collectionView.dequeueReusableCellWithReuseIdentifier(reuseIdentifier, forIndexPath: indexPath) as! viewcell

这会有所帮助。