Swift scrollViewDidScroll未在具有自定义布局的CollectionView中调用
我想在用户到达我的CollectionView末尾时加载更多数据。不幸的是,从未调用scrollViewDidScroll 对于我的CollectionView,我使用自定义布局,我认为问题可能在于:Swift scrollViewDidScroll未在具有自定义布局的CollectionView中调用,swift,uicollectionview,uiscrollview,Swift,Uicollectionview,Uiscrollview,我想在用户到达我的CollectionView末尾时加载更多数据。不幸的是,从未调用scrollViewDidScroll 对于我的CollectionView,我使用自定义布局,我认为问题可能在于: if let layout = exploreCollectionView.collectionViewLayout as? CustomLayout { layout.delegate = self } 我的班级: class MainViewControlle
if let layout = exploreCollectionView.collectionViewLayout as? CustomLayout {
layout.delegate = self
}
我的班级:
class MainViewController: UIViewController, UIScrollViewDelegate { .....
我想检查scrollViewDidScroll功能是否有效:
// Check if a user wants to load more data at the bottom
func scrollViewDidScroll(_ scrollView: UIScrollView) {
print("scrolled")
}
如何在自定义布局中实现scrollViewDidScroll?
scrollViewDidScroll
是一种UIScrollViewDelegate
方法。因此,您需要使self(MyViewController
)成为collectionview的代理:
exploreCollectionView.delegate=self
然后,例如在扩展中:
extension MyViewController: UIScrollViewDelegate {
func scrollViewDidScroll(_ scrollView: UIScrollView) {
print("scrolled")
}
}
谢谢你,科恩。我认为如果让layout=exploreCollectionView.collectionViewLayout作为,会有问题吗?CustomLayout{layout.delegate=self}