Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

IBOutet is not being recognized as an UIimage

I am trying to allow users to take photos when the button action is clicked. Ive added an UIImage into storyboard which has a UIImage linked to my View Controller.I’ve set the name for this image as imageView, yet when I implement imageView.image = image I am getting an error "Cannot find ‘imageView’ in scope" i’ve also tried to set this as self.imageView = image and I get the error "Cannot find self in scope". I am unsure why my imageView which is connected to the @IBOutlet is not being found?

    import UIKit

class HomeScreenViewController: UIViewController, UINavigationControllerDelegate, UIImagePickerControllerDelegate {
     @IBOutlet weak var imageView: UIImageView!
     var button: UIButton! {
         imageView.backgroundColor = .secondarySystemBackground
        self.button.backgroundColor = .systemBlue
        
    }
    override func viewDidLoad() {
        super.viewDidLoad()
        
    }
    @IBAction func didTapButton(){
        let picker = UIImagePickerController()
        picker.sourceType = .camera
        picker.delegate = self
        present(picker, animated: true)
    }
}

func imagePickerControllerDidCancel(_ picker: UIImagePickerController){
    picker.dismiss(animated: true, completion: nil)
}
func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [UIImagePickerController.InfoKey: Any])      {
    picker.dismiss(animated: true, completion: nil)
    
    guard let image = info[UIImagePickerController.InfoKey.originalImage] as? UIImage  else {
        return
    }
    
    imageView.image = image
    
}

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

You function is not inside your class!! You should put inside it:

class HomeScreenViewController: UIViewController, UINavigationControllerDelegate, UIImagePickerControllerDelegate {
    func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [UIImagePickerController.InfoKey: Any]){
       // any code
    }
}
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading