我想为我的collectionView中的每个索引项目创建不同的单元格,并且我试图将它们作为它们各自的单元格向下翻转以访问它们的变量。下面 该代码输出这个错误“无法分配类型的值‘LiveCell.Type’为类型‘UICollectionViewCell’”Swift中的自定义单元格UICollectionView
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let identifier: String
let cellName: UICollectionViewCell
if indexPath.item == 1 {
identifier = LiveCellId
cellName = LiveCell
} else if indexPath.item == 2 {
identifier = LiveCellId
cellName = LiveCell
} else {
identifier = FeedCellId
cellName = FeedCell
}
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: identifier, for: indexPath) as! cellName //Trying to downcast cell from the variable called cellName
cell.homeController = self
return cell
}
是否有一个解决方案。在此先感谢
伟大的作品。谢谢 –