我认为这个问题很容易被归类为复制品,但在搜索后无法找到答案。
我的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 时,应用程序崩溃了
答案 0 :(得分:0)
如果操作应该在ChooseProfilePhotoPicker
的实例中运行,则必须相应地设置目标:
let tapGesture = UITapGestureRecognizer(target: chooseProfilePhotoPicker, action: #selector(chooseProfilePhotoPicker.iconImageViewTapped(_:)))