Hi, I have a VC that has multiple UIImageView's with a button for each UIImageView. As I can't declare imagePickerController multiple times, I added a sentence at the end of the imagePickerController stating: imageTaken = image, which imageTaken has been declared as a variable.
All is good till now, when I take a picture, although I'm using the DispatchQueue.main.sync, all the lines are function as executed at the same time. The reason I know this is that the first time I take a pic, nothing is stored in the UIImageView, the consecutive times, the second I click the button, the image shows in the UIImageView, then it goes to the camera, if I click cancel, then the image shows up from the previous click. As far as I understand, all the lines in the function are executed at the same time, that's why the image stays in the variable, but it doesn't show up in the UIImageView because it didn't have time to be saved in the variable before the line was executed. Can someone help please? If what I'm doing is wrong, all I want to do is to take multiple pictures to be shown on different UIImageViews on the same VC. Thanks
@IBAction func takeClientIdCardFrontPic() { DispatchQueue.main.async { let picker = UIImagePickerController() picker.sourceType = .camera picker.delegate = self self.present(picker, animated: true) self.clientIdCardFrontImage.image = self.imageTaken } }
extension ReportViewController: UIImagePickerControllerDelegate, UINavigationControllerDelegate {
func imagePickerControllerDidCancel(_ picker: UIImagePickerController) { picker.dismiss(animated: true, completion: nil) }
func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [UIImagePickerController.InfoKey : Any]) { picker.dismiss(animated: true, completion: nil) guard let image = info[UIImagePickerController.InfoKey.originalImage] as? UIImage else{ return } imageTaken = image } }