【发布时间】:2020-03-31 22:50:52
【问题描述】:
我想创建一个包含两个不同单元格的 collectionView。第一个单元格应显示一次,第二个单元格应尽可能频繁地显示,因为数组很大。结果应该类似于附加链接中的图像。这也是一个示例代码,可以更好地理解我的问题。感谢所有帮助我的人!!! ????
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
switch indexpath { // No indexpath in numberofitemsinsection!
case 0:
return 1 //display one time the first cell
default:
return images.count // display as often as the array is large the second cell
}
}
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
switch indexPath.row {
case 0:
let cell = imageCollectionView.dequeueReusableCell(withReuseIdentifier: "addImageCell", for: indexPath)
return cell
default:
let cell = imageCollectionView.dequeueReusableCell(withReuseIdentifier: "imageCell", for: indexPath) as! ImageCell
cell.imageView.image = images[indexPath.row]
cell.delegate = self
cell.selectedAtIndex = indexPath
return cell
}
}
【问题讨论】:
标签: ios swift uicollectionview uicollectionviewcell