ipios
ipios

Reputation: 31

UIView setImage:]: unrecognized selector sent to instance

import UIKit
import MobileCoreServices

class ViewController: UIViewController, UIImagePickerControllerDelegate, UINavigationControllerDelegate{
    let imagePicker = UIImagePickerController()


    @IBOutlet var ImageView: UIImageView!
    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view, typically from a nib.
        imagePicker.delegate = self
    }



    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }


    // MARK: Actions


    @IBAction func Select(sender: AnyObject) {

        //imagePicker.sourceType =
          //  UIImagePickerControllerSourceType.PhotoLibrary
        //imagePicker.mediaTypes = [kUTTypeImage as String]
        imagePicker.allowsEditing = false
        self.presentViewController(imagePicker, animated: true, completion: nil)

    }

    func imagePickerController(picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : AnyObject]) {


        if  let image = info[UIImagePickerControllerOriginalImage] as? UIImage {
            ImageView.contentMode = .ScaleAspectFit
            ImageView.image = image
        }

        self.dismissViewControllerAnimated(true, completion: nil)

    }

    func imagePickerControllerDidCancel(picker: UIImagePickerController) {
        self.dismissViewControllerAnimated(true, completion: nil)
    }
}

I stumped on why the UIImage picked by the PickerController is not set to UIImageView. Can any one please provide insight into what I am missing here?

Upvotes: 0

Views: 5134

Answers (2)

AndyDunn
AndyDunn

Reputation: 1084

Just for future reference the other reason this might happen is because you've accidentally connected the wrong UI element to your UIImageView property.

For example I dragged a NSConstraint to the UIImageView, and got the same error.

Upvotes: 1

jtbandes
jtbandes

Reputation: 118681

You have @IBOutlet var ImageView: UIImageView! in your code, but you are getting the error "UIView setImage:]: unrecognized selector". This means that you configured your view in Interface Builder as a UIView, rather than a UIImageView. You need to set up a UIImageView to be able to set the image.

Upvotes: 7

Related Questions