我目前正在尝试创建一种方法,以删除集合视图中1个后面的indexPath处的项目。到目前为止,我已经使用了一些帮助来创建一个使用滚动视图did scroll函数的方法,通过当前图像方法计算用户所在的图像。现在我需要一种方法来计算用户所在的单元格。以下是我的代码>
var currentImage = 0
func scrollViewDidScroll(_ scrollView: UIScrollView) {
let x = floor(myCollectionView.contentOffset.x / view.frame.width)
if Int(x) != currentImage {
currentImage = Int(x)
//print(currentImage)
}
if currentImage > 0 {
for collectionCell in myCollectionView.visibleCells as [UICollectionViewCell] {
let indexPath = myCollectionView.indexPath(for: collectionCell as UICollectionViewCell)!
let indexPathOfLastItem = (indexPath?.item)! - 1
let indexPathOfItemToDelete = IndexPath(item: (indexPathOfLastItem), section: 0)
imageArray.remove(at: 0)
myCollectionView.deleteItems(at: [indexPathOfItemToDelete])
currentImage = 1
scrollViewDidScroll
方法中打印可见单元格没有任何关系。 - rmaddyscrollViewDidScroll
委托方法无关。您实际上想在哪个方法中删除单元格并确定其索引路径? - rmaddy