Delegado rápido entre dois VC sem segue
Eu tenho 3 aulas:
ChatLogControollerGetImageFromLibraty (classe NSObject)ImagePreviewViewControllerQuero pressionar um clipe do primeiro VC e abrir a biblioteca de mídia para escolher uma imagem. Em seguida, a imagem selecionada é passada para o terceiro VC como um previewController. Então, se eu selecionar 'concluído', quero passar para o primeiro VC.
1º VC
class ChatLogControoller: UICollectionViewController, UICollectionViewDelegateFlowLayout, NSFetchedResultsControllerDelegate, UINavigationControllerDelegate, UIImagePickerControllerDelegate, DataSentDelegate {
func recievePhoto(data: UIImage) {
imageFromView = data
print("-------\(imageFromView = data)")
}
override func viewDidLoad() {
super.viewDidLoad()
let vc = ImagePreviewController()
self.vc.delegate = self
}
2ª classe é apenas selecionador de imagem, então eu passo a imagem para o 3º VC e essa imagem aparece no imageView do 3º VC com sucesso!
meu terceiro VC
protocol DataSentDelegate {
func recievePhoto(data: UIImage)
}
class PreviewController: UIViewController, UIScrollViewDelegate {
var delegate : DataSentDelegate? = nil
var aImageView: UIImageView!
var aImage: UIImage!
override func viewDidLoad() {
super.viewDidLoad()
navigationItem.rightBarButtonItem = UIBarButtonItem(title: "Add", style: .plain, target: self, action:, #selector(actionSend))
navigationItem.leftBarButtonItem = UIBarButtonItem(title: "Cancel", style: .plain, target: self, action: #selector(actionBack))
}
@objc func actionBack() {
dismiss(animated: false, completion: nil)
}
@objc func actionSend() {
let data = aImageView.image
delegate?.recievePhoto(data: data!)
dismiss(animated: true, completion: nil)
}