无法识别的选择器发送到实例

时间:2017-08-13 09:49:10

标签: swift

我认为这个问题很容易被归类为复制品,但在搜索后无法找到答案。

我的cellForRowAt

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

ChooseProfilePhotoPicker类:

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)
    }
}
当我点击iconImageView

时,

应用程序崩溃了

1 个答案:

答案 0 :(得分:0)

如果操作应该在ChooseProfilePhotoPicker的实例中运行,则必须相应地设置目标

let tapGesture = UITapGestureRecognizer(target: chooseProfilePhotoPicker, action: #selector(chooseProfilePhotoPicker.iconImageViewTapped(_:)))