集合视图单元格无法识别其出口

Collection view cell doesn't recognize its outlet

我有一个集合视图控制器 ItemCollectionVC,我想用图像填充它的单元格,我是这样设置的:

override func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
    let cell = collectionView.dequeueReusableCell(withReuseIdentifier: reuseIdentifier, for: indexPath)
    cell.cellImage.image = dataSourceItems[indexPath.row].image
    // Error

    return cell
}

Hoever, there's an error: Value of type UICollectionViewCell have no member cellImage

单元格是自定义单元格ItemCell,我在故事板中设置了自定义class,这里是ItemCell:

class ItemCell: UICollectionViewCell {

    @IBOutlet weak var cellImage: UIImageView!

}

我还将插座连接到单元格的图像视图。

所以我不明白为什么会出现错误,有人知道吗?

只有一个错误,您需要为单元格 as! ItemCell

定义 class
  let cell = collectionView.dequeueReusableCell(withReuseIdentifier: reuseIdentifier, for: indexPath) as! ItemCell