func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell=colView1.dequeueReusableCell(withReuseIdentifier:"cell",for: indexPath) as! MyCollectionViewCell
cell.Image.image=UIImage (named: imagehome[indexPath.row]) //error
if (collectionView==colView2){
let cell = colView2.dequeueReusableCell(withReuseIdentifier:"cell1", for:indexPath) as! CollectionViewCell2
cell.Image1.image = UIImage (named: imageHome2[indexPath.row])
cell.Image1.layer.cornerRadius = cell.frame.height/2
return cell
}
return cell
}
如何解决此错误?
1条答案
按热度按时间daupos2t1#
重写代码以获取不同的图像,具体取决于您为哪个集合视图提供单元格:
您的代码还试图从colView1中移出单元格,即使请求来自colView2。那没用的