i am trying to send an image from my collectionViewCell imageView to an imageView in another VC through delegation and Protocol. I cannot figure out why this isn't working properly?
The sending VC is: TrainersViewController
The recieving VC is: BioViewController
Here is my protocol:
protocol TrainersViewControllerDelegate: class {
func trainersViewController(controller: TrainersViewController, didFinishSendingImage trainer:TrainerArray)
}
class TrainersViewController: UIViewController, UICollectionViewDataSource, UICollectionViewDelegate, AddNewTrainerViewControllerDelegate {
weak var delegate: TrainersViewControllerDelegate?
}
Here is my Receiving class:
class BioViewController: UIViewController, TrainersViewControllerDelegate {
@IBAction func backToTrainersButton(sender: AnyObject) {
dismissViewControllerAnimated(true, completion: nil)
}
override func viewDidLoad() {
super.viewDidLoad()
}
@IBOutlet weak var bioImage: UIImageView!
func trainersViewController(controller: TrainersViewController, didFinishSendingImage trainer: TrainerArray) {
trainer.trainerImage! = bioImage as! UIImage
}
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
if segue.identifier == "bioSegue" {
let navigationController = segue.destinationViewController as! UINavigationController
let controller = navigationController.topViewController as! TrainersViewController
controller.delegate = self
}
}
}
Finally here is the button within the collectionViewCell that i am calling upon to make this happen:
@IBAction func bioSegueButton(sender: AnyObject) {
let index = sender.tag
let trainer = trainers[index]
print(trainer.name)
delegate?.trainersViewController(self, didFinishSendingImage: trainer)
performSegueWithIdentifier("bioSegue", sender: self)
}
Why is this not sending my image across into the imageView of the other VC?