I have 2 UIImageView, named "artistImage" and "albumImage", each one contains 1 tap gesture and all the gestures are connected to 1 @IBAction, named "artistImageTap". Those tap gestures are drag from object library and place over my ImageView.
My app have a list of artists, albums and songs, when a song is tapped, the app moves to this view and display its details. If I click the add button, the app moves to this view but this time all the text fields are editable, the images are default and user can tap them to select image from library to create new song.
My problem is I don't know how to identify which UIImageView is tapped. As you can see in the picture, I tried picker.restorationIdentifier but it always returns nil.
@IBAction func artistImageTap(_ sender: UITapGestureRecognizer) {
let imagePickerController = UIImagePickerController()
// Only allow photos to be picked, not taken.
imagePickerController.sourceType = .photoLibrary
// Make sure ViewController is notified when the user picks an image.
imagePickerController.delegate = self
present(imagePickerController, animated: true, completion: nil)
}
func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : Any]) {
// The info dictionary may contain multiple representations of the image. You want to use the original.
guard let selectedImage = info[UIImagePickerControllerOriginalImage] as? UIImage else {
fatalError("Expected a dictionary containing an image, but was provided the following: \(info)")
}
// Set photoImageView to display the selected image.
if picker.restorationIdentifier == "artistImage" {
artistImage.image = selectedImage
} else {
albumImage.image = selectedImage
}
// Dismiss the picker.
dismiss(animated: true, completion: nil)
}
Every help is appreciated!!
sender.view
and setup atag
in yourUIImageView
, after that you can usesender.view.tag
as identifier – Reinier MeliandebugPrint(sender.view)
and let me know what prints @hell2809 – Reinier Melian