In my viewModel i have this function which gives me the above class but with the newest images array without the previous ones, since its paginated.
func updateUserImages(with userID: Int?, and nextMaxID: String, onSuccess: @escaping (ProfileImages) -> Void) {
userService.getUserImages(with: userID, nextMaxId: nextMaxID) { (feedResponse) in
let newProfileImages = ProfileImages(nextMaxID: feedResponse.nextMaxId, images: feedResponse.items)
onSuccess(newProfileImages)
}
}
And in my View Controller, in the scroll delegate of adapter, I have your paradigm from LoadMoreSectionController
extension ProfileViewController: UIScrollViewDelegate {
func scrollViewWillEndDragging(_ scrollView: UIScrollView,
withVelocity velocity: CGPoint,
targetContentOffset: UnsafeMutablePointer<CGPoint>) {
guard let object = self.profileViewModel.viewData.value[1] as? ProfileImages,
let nextMaxID = object.nextMaxID,
var oldImages = object.images else { return }
let distance = scrollView.contentSize.height - (targetContentOffset.pointee.y + scrollView.bounds.height)
if !loading && distance < 200 {
loading = true
adapter.performUpdates(animated: true, completion: nil)
DispatchQueue.global(qos: .default).async {
DispatchQueue.main.async {
self.profileViewModel.updateUserImages(with: self.userService.user.pk, and: nextMaxID, onSuccess: { profileImages in
self.loading = false
oldImages.append(contentsOf: profileImages.images ?? []) // here i update the previews array by appending the new arrays
object.images = oldImages // and here i replace the previews array with the new one which has all the images.
object.nextMaxID = profileImages.nextMaxID
self.adapter.performUpdates(animated: true, completion: nil) // Although if i use `self.adapter.reloadData()` its not crashing although i read on the docs that it's not a proper way to reload stuff.
})
}
}
}
}
}
New issue checklist
README
and documentationGeneral information
IGListKit
version: 3.4.0Hello. I have this issue with IGList kit. So in my project i have a "Loading more" functionality about images downloaded from my API, paginated.
So there is a class which holds the
In my viewModel i have this function which gives me the above class but with the newest images array without the previous ones, since its paginated.
And in my View Controller, in the scroll delegate of adapter, I have your paradigm from LoadMoreSectionController
And when i scroll down it crashes.
Am I missing something ?