创建具有未知类型的图像格式是一个错误

时间:2017-02-07 04:28:37

标签: ios swift uiimagepickercontroller

到目前为止,我已尝试过所有在线解决方案,但似乎都没有。这是我的类(视图控制器已正确初始化。)我的代码似乎没有到达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)
    }
}

0 个答案:

没有答案