قالب وردپرس درنا توس
Home / IOS Development / IOS – How to paginate when using PHAsset to retrieve User Photo Library

IOS – How to paginate when using PHAsset to retrieve User Photo Library



I ask the same question as here
I do not understand how to implement for solution.
I have tried the following

  fileprivate func fetchPhotos (indexSet: IndexSet) {
leave allPhotos = PHAsset.fetchAssets (with: .image, alternatives: assetsFetchOptions ())
DispatchQueue.global (qos: .background) .async {
allPhotos.enumerateObjects (at: indexSet, options: NSEnumerationOptions.current, using: {(asset, count, stop)
la imageManager = PHImageManager.default ()
let targetSize = CGSize (width: 200, height: 200)
leave options = PHImageRequestOptions ()
options.isSynchronous = true
imageManager.requestImage (for: asset, targetSize: targetSize, contentMode: .aspectFit, alternatives: options, resultSeller: {(image, info) in
if let picture = image {
self.images.append (image)
self.assets.append (asset)

if self.selectedImage == nil {
self.selectedImage = image
}
}
DispatchQueue.main.async {
self.collectionView.reloadData ()
self.hud.dismiss ()
}

})
})
}
}

In cellForItemAt I tried to double the indexes so the next 1

0 would load. The result I received was an infinite repetition of the first 10 posts.
Can anyone, please show the right way to use this.


Source link