Error: unrecognized selector but my outlets seem to be correct

Viewed 31

I am getting the error: Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UIViewController didTapButton:]: unrecognized selector sent to instance 0x7fac8e719530' terminating with uncaught exception of type NSException

However, I have connected my button to an IBAction and it appears correct in the story board.

override func viewDidLoad() {
    super.viewDidLoad()
    
    let retrieveData = UserDefaults.standard.data(forKey: "tasks")
    
    tasks = try! JSONDecoder().decode([Task].self, from: retrieveData!)
    // Do any additional setup after loading the view.
  
  //  titleField.delegate = self
   // altTextField.delegate = self
   // hoursField.delegate = self
   // minutesField.delegate = self
}

@IBAction func didTapButton(_ sender: Any) {
    let vc = UIImagePickerController()
    vc.sourceType = .photoLibrary
    vc.delegate = self
    //vc.allowsEditing = true
    present(vc, animated: true)
}

func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [UIImagePickerController.InfoKey : Any]) {
    
    if let image = info[UIImagePickerController.InfoKey.originalImage]as? UIImage {
        //taskImage.image = image
        print("image selected: ")
        print(image)
    }
    picker.dismiss(animated: true, completion: nil)
}

func imagePickerControllerDidCancel(_ picker: UIImagePickerController) {
    picker.dismiss(animated: true, completion: nil)
}

}

code

storyboard

How do I fix this error?

0 Answers
Related