我一直在开发照片存储应用程序,会从我的火力地堡数据库中的图像链接,将它们存储在以一个数组,然后通过这个数组得到从图像中运行相应的Firebase存储使用阵列中的链接。中的CollectionView火力地堡存储的getData负荷图像无序
但是,即使代码按顺序通过链接运行,getData函数也会加载图像。我不知道为什么发生这种情况,尽管我最初的想法是图像按大小顺序加载/加载时间最短。这是我的代码。
for link in Constants.officialLinksArray {
let storage = Storage.storage().reference(forURL: link)
// Download the data, assuming a max size of 1MB (you can change this as necessary)
storage.getData(maxSize: 10 * 1024 * 1024) { (data, error) -> Void in
// Create a UIImage, add it to the array
if let error = error {
print(error)
} else {
//print(self.imageCount)
let loadedImage = UIImage(data: data!)
self.photoArray.append(loadedImage!)
Constants.officialPhotoArray = self.photoArray
self.buttonArray.append(self.photoArray.count)
self.collectionView.reloadData()
//print(self.photoArray)
}
}
}
任何帮助表示赞赏。谢谢!
而不是在这里下载图像在cellforrow与异步和它的更多信息请参阅此:https://stackoverflow.com/questions/24231680/loading-downloading-image-from-url-on-swift –