【发布时间】:2017-08-08 02:37:48
【问题描述】:
所以现在我正在尝试让集合视图单元格使用照片库来更新照片。这是我的代码:
import UIKit
class viewCellVC: UICollectionViewCell, UIImagePickerControllerDelegate, UINavigationControllerDelegate {
@IBOutlet var bookImage: UIImageView!
@IBAction func addImage(_ sender: Any) {
let imagePicker = UIImagePickerController()
imagePicker.delegate = self
imagePicker.sourceType = UIImagePickerControllerSourceType.photoLibrary
imagePicker.allowsEditing = false
self.window?.rootViewController?.present(imagePicker, animated: true, completion: nil)
}
func imagePickerControllerDidCancel(_ picker: UIImagePickerController) {
picker.dismiss(animated: true, completion: nil)
}
func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : Any]) {
let image = info[UIImagePickerControllerOriginalImage] as! UIImage
bookImage.image = image
picker.dismiss(animated: true, completion: nil)
}
}
但是,当我尝试运行代码并更新图片时,模拟器无法打开照片库,而是收到以下错误消息(没有结束应用程序,只是无法运行照片库):
2017-08-07 21:35:31.709183-0500 ChuBookElf[2817:66569] Warning: Attempt to present <UIImagePickerController: 0x7f907e0bf800> on <ChuBookElf.ViewController: 0x7f907de072c0> whose view is not in the window hierarchy!
谁能告诉我我做错了什么?我已经做了好几个小时了。
For Reference, here is what the collection view cell looks like
【问题讨论】:
标签: ios swift uicollectionview uiimagepickercontroller