Ios UICollectionView don';在分页期间更新单元格

Ios UICollectionView don';在分页期间更新单元格,ios,swift,uicollectionview,uicollectionviewcell,Ios,Swift,Uicollectionview,Uicollectionviewcell,我有一个启用水平分页的UICollectionView,每个单元格填充整个屏幕并包含一个ImageView < >我想更新两个参与分页的单元格(如果从第0页转到第1页,我想在中间部分更新它们) 因此,我覆盖了以下方法: public func scrollViewWillBeginDragging(_ scrollView: UIScrollView) { let pageWidth = collectionView.frame.size.width var cu

我有一个启用水平分页的
UICollectionView
,每个单元格填充整个屏幕并包含一个
ImageView

< >我想更新两个参与分页的单元格(如果从第0页转到第1页,我想在中间部分更新它们)

因此,我覆盖了以下方法:

public func scrollViewWillBeginDragging(_ scrollView: UIScrollView) {
        let pageWidth = collectionView.frame.size.width
        var currentPage = collectionView.contentOffset.x / pageWidth
        if (0.0 != fmodf(Float(currentPage), 1.0)) {
            currentPage += 1
        }

        let indexPath = IndexPath(row: Int(currentPage), section: 0)
        guard let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "MyCell", for: indexPath) as? MyCell else {
            return
        }

        // This cell is moving out of screen
        cell.image.isHidden = true

    }

问题是,如果我打印cell.image.isHidden,图像隐藏状态的任何更改都不会生效。它显示正确的状态,但用户界面没有更新。

替换每个

guard let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "MyCell", for: indexPath) as? MyCell else {
        return
}

guard let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "MyCell", for: indexPath) as? MyCell else {
        return
}
guard let cell = collectionView.cellForItem(at:indexPath) as? MyCell else {
        return
}