【发布时间】:2020-06-20 15:57:47
【问题描述】:
我正在创建这个应用程序,它会拍照并将其显示在 UIImageView 中。当我按下保存按钮时,它应该将图像保存到文档目录。然后我希望能够在我的收藏视图中检索这些图像。我有下面的代码保存图像,但我将如何在我的收藏视图中检索它?谢谢!
第一个视图控制器 - 保存图像
func saveImage(image: UIImage) -> String {
let imageData = NSData(data: image.pngData()!)
let paths = NSSearchPathForDirectoriesInDomains(FileManager.SearchPathDirectory.documentDirectory, FileManager.SearchPathDomainMask.userDomainMask, true)
let docs = paths[0] as NSString
let uuid = NSUUID().uuidString + ".png"
let fullPath = docs.appendingPathComponent(uuid)
_ = imageData.write(toFile: fullPath, atomically: true)
return uuid
}
@IBAction func didPressSaveButton(_ sender: Any) {
for _ in self.images {
_ = self.saveImage(image: self.imageView.image!)
}
}
第二视图控制器 - 检索图像
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return
}
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "customCell", for: indexPath) as!
MyPicturesCollectionViewCell
return cell
}
【问题讨论】:
标签: swift uicollectionview uiimageview