英文:
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:
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论