셀의 마지막 줄이 나타날 때 쯤 데이터 추가해줌
// ...
func collectionView(_ collectionView: UICollectionView, willDisplay cell: UICollectionViewCell, forItemAt indexPath: IndexPath) {
self.viewModel.loadIfMoreNeeded(index: indexPath.item)
}
// ...
// ...
func loadIfMoreNeeded(index: Int) {
// 데이터 개수-6 >>> 3*2=6 >>> 두 줄 전에 >>> 미리 로드할거임
if index > data.count - 6 {
self.load() // 데이터 추가하는 함수
}
}
// ...