我正在尝试将PSAssets
转换为UIImage
,并且一直工作到3个小时,然后发生了一些事情(不知道我做了什么),现在我得到的只是错误:
线程17:致命错误:索引超出范围
它使我疯狂了几个小时,我无法弄清楚。
func convertAssetToImages() -> Void {
if !selectedAssets.isEmpty {
photosArray = []
for i in 0..<selectedAssets.count {
let manager = PHImageManager.default()
let option = PHImageRequestOptions()
option.version = .current
option.resizeMode = .exact
option.deliveryMode = .fastFormat
var thumbnail = UIImage()
option.isSynchronous = true
manager.requestImage(for: selectedAssets[i], targetSize: PHImageManagerMaximumSize, contentMode: .aspectFill, options: option, resultHandler: {(result, info) -> Void in
thumbnail = result!
})
let data = UIImageJPEGRepresentation(thumbnail, 0.7)
let newImage = UIImage(data: data!)
self.photosArray.append(newImage! as UIImage)
DispatchQueue.main.async {
self.collectionView.reloadData()
}
}
}
}
答案 0 :(得分:-1)
您正在for循环内重新加载集合视图..可能存在问题.. plz使其退出for循环,否则请检查numberof行,您要返回的数组