由于某些原因,尽管遵守了协议override willDisplayCell forItemAt,但仍无法使用UICollectionViewDelegate。
试图实现自定义UICollectionFlowLayout。通过使用此委托方法,需要能够通过api延迟加载。

我取了raywenderlich的最后代码- https://www.raywenderlich.com/4829472-uicollectionview-custom-layout-tutorial-pinterest用于Pinterest布局,并添加了
override func collectionView(_ collectionView: UICollectionView, willDisplay cell: UICollectionViewCell, forItemAt indexPath: IndexPath) {
print("fetch")
}方法:每次翻卷CV时,打印一次。
对于工作副本,有重写关键字。
PS>这个问题现在已经解决了,原来RW在使用UICollectionViewController,而我在普通的ViewController上使用了CollectionView。因此,他们不得不使用覆盖,而我不需要!
发布于 2019-11-28 05:31:04
collectionView:willDisplayCell:forItemAtIndexPath:是一种协议功能。所以你不需要重写。移除覆盖。
发布于 2019-11-28 07:52:34
首先,你不需要override
在这里
您的类只是ViewController,UIViewController的一个子类与您给出的引用不同,PhotoStreamViewController是UICollectionViewController的一个子类
确保您没有确认控制器定义中的冗余委托UICollectionViewDelegate**,,并且在扩展时再次确认(已粘贴的屏幕快照)**
我已经测试了你给出的链接中的样本,它运行得很好。
不用说,请各位代表一次同意:
class ViewController: UIViewController, UICollectionViewDelegate, UICollectionViewDataSource, PinterestLayoutDelegate {
//all the required delegate methods
}https://stackoverflow.com/questions/59081590
复制相似问题