Cannot assign value of type 'SignUpViewController' to type '(UIImagePickerControllerDelegate & UINavigationControllerDelegate)?'

huangapple go评论71阅读模式
英文:

Cannot assign value of type 'SignUpViewController' to type '(UIImagePickerControllerDelegate & UINavigationControllerDelegate)?'

问题

@objc func presentPicker(){
    let picker = UIImagePickerController()
    picker.sourceType = .photoLibrary
    picker.allowsEditing = true
    picker.delegate = self //error
    self.present(picker, animated: true, completion: nil)
}

extension SignInViewController: UIImagePickerControllerDelegate, UINavigationControllerDelegate {
    func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [UIImagePickerController.InfoKey : Any]) {
        if let imageSelected = info[.editedImage] as? UIImage {
            avatar.image = imageSelected
        }

        if let imageOriginal = info[.originalImage] as? UIImage {
            avatar.image = imageOriginal
        }

        picker.dismiss(animated: true, completion: nil)
    }
}

I think(!) I have copied the tutorial code correctly but get two errors in my ImagePicker struct

//Error: Cannot assign value of type 'SignUpViewController' to type '(UIImagePickerControllerDelegate & UINavigationControllerDelegate)?'

I'm using Xcode 13.

英文:
@objc func presentPicker(){
let picker = UIImagePickerController()
picker.sourceType = .photoLibrary
picker.allowsEditing = true
picker.delegate = self //error
self.present(picker, animated: true, completion: nil)
}


extension SignInViewController: UIImagePickerControllerDelegate, UINavigationControllerDelegate {
func imagePickerController(\_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: \[UIImagePickerController.InfoKey : Any\]) {
if let imageSelected = info\[UIImagePickerController.InfoKey.editedImage\] as? UIImage {
avatar.image = imageSelected}

        if let imageOriginal = info[UIImagePickerController.InfoKey.originalImage] as?
            UIImage {
            avatar.image = imageOriginal
        }
        
        picker.dismiss(animated: true, completion: nil)
        
    }

}

I think(!) I have copied the tutorial code correctly but get two errors in my ImagePicker struct

//Error: Cannot assign value of type 'SignUpViewController' to type '(UIImagePickerControllerDelegate & UINavigationControllerDelegate)?'

I'm using Xcode 13.

答案1

得分: 0

在以下代码行:

> picker.delegate = self

你已将SignUpViewController对象分配给了picker的代理,并且你已将UIImagePickerControllerDelegate继承到了SignInViewController类,而不是SignUpViewController类。

请将SignInViewController:的扩展替换为SignUpViewController:

英文:

At line

> picker.delegate = self

You have assigned SignUpViewController object to picker delegate and you have inherited UIImagePickerControllerDelegate into SignInViewController class instead of SignUpViewController

replace extension SignInViewController: with extension SignUpViewController:

huangapple
  • 本文由 发表于 2023年2月6日 08:58:30
  • 转载请务必保留本文链接:https://go.coder-hub.com/75356553.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定