0

I suppose this question could be easily classed as a duplicate but can't find answer after searching.

inside cellForRowAt for my tableView

let chooseProfilePhotoPicker = ChooseProfilePhotoPicker(rootVC: self)
chooseProfilePhotoPicker.cropVC.delegate = self
let tapGesture = UITapGestureRecognizer(target: self, action: #selector(chooseProfilePhotoPicker.iconImageViewTapped(_:)))
cell.iconImageView.addGestureRecognizer(tapGesture)

And the ChooseProfilePhotoPicker class:

class ChooseProfilePhotoPicker: NSObject, UIImagePickerControllerDelegate, UINavigationControllerDelegate {

    var rootController: UIViewController

    init(rootController: UIViewController) {
        self.rootController = rootController
    }

    func iconImageViewTapped(_ recognizer: UITapGestureRecognizer) {

        var pickerController = UIImagePickerController()
        pickerController.delegate = self
        pickerController.sourceType = UIImagePickerControllerSourceType.photoLibrary

        rootController.present(myPickerController!, animated: true, completion: nil)
    }
}

app crashes when I tap the iconImageView

luke
  • 2,743
  • 4
  • 19
  • 43
  • Possible duplicate of [How can I debug 'unrecognized selector sent to instance' error](https://stackoverflow.com/questions/25853947/how-can-i-debug-unrecognized-selector-sent-to-instance-error) – Cœur Jul 08 '19 at 05:53

1 Answers1

0

If the action is supposed to run in in the instance of ChooseProfilePhotoPicker you have to set the target accordingly:

let tapGesture = UITapGestureRecognizer(target: chooseProfilePhotoPicker, action: #selector(chooseProfilePhotoPicker.iconImageViewTapped(_:)))
vadian
  • 274,689
  • 30
  • 353
  • 361