到目前为止,我已尝试过所有在线解决方案,但似乎都没有。这是我的类(视图控制器已正确初始化。)我的代码似乎没有到达imagePickerController
方法,并抛出此问题标题中提到的错误。有什么想法吗?
class ImageCell : UICollectionViewCell
{
@IBOutlet weak var myImage: UIImageView!
var ic:ImageController?
func singleTap(_ sender:UITapGestureRecognizer)
{
self.selectImageFromPhotoLibrary()
}
func selectImageFromPhotoLibrary()
{
let imagePickerController = UIImagePickerController()
imagePickerController.sourceType = .photoLibrary
imagePickerController.delegate = ic
ic?.present(imagePickerController, animated:true, completion:nil)
}
func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : Any])
{
guard let selectedImage = info[UIImagePickerControllerOriginalImage] as? UIImage else {
fatalError("Expected a dictionary containing an image, but was provided the following: \(info)")
}
myImage.image = selectedImage
ic?.dismiss(animated: true, completion: nil)
}
func imagePickerControllerDidCancel(_ picker: UIImagePickerController) {
// Dismiss the picker if the user canceled.
ic?.dismiss(animated: true, completion: nil)
}
}