我想这个问题很容易被归类为重复问题,但搜索后找不到答案。
在我的tableView
的cellForRowAt
内
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 时应用程序崩溃
最佳答案
如果操作应该在ChooseProfilePhotoPicker
实例中运行,您必须相应地设置目标:
let tapGesture = UITapGestureRecognizer(target: chooseProfilePhotoPicker, action: #selector(chooseProfilePhotoPicker.iconImageViewTapped(_:)))
关于swift - 无法识别的选择器发送到实例,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45659079/