I am trying to pass on information via unwind segue. I have a custom table view and then I click it, it unwinds the segue to the previous segue.
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
let indexPath = self.selectedIndex
self.performSegue(withIdentifier: "SwapBack", sender: indexPath)
}
But I also want to be able to pass data to the previous view controller when I unwind the segue:
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
if let indexPath = sender as? IndexPath {
let vc = segue.destination as! PopUpViewController
let post = self.posts[indexPath.row] as! [String: AnyObject]
let Booked = post["title"] as? String
let Authors = post["Author"] as? String
let Prices = post["Price"] as? String
let imageNames = post["image"] as? String
self.Booked = Booked
self.Authors = Authors
self.imageNames = imageNames
self.Prices = Prices
vc.SelectABook.isHidden = true
vc.SelectBookButton.backgroundColor = UIColor.clear
print("Is this working?")
}
}
In the destination segue. This is the original function that initiates the unwind segue
@IBAction func Swap (_ sender: UIStoryboardSegue) {
if sender.source is SwapViewController{
if let senderVC = sender.source as? SwapViewController{
self.SwapTitle.text = senderVC.Booked
self.SwapTax.text = "$0.50"
self.SwapPrice.text = senderVC.Prices
if let stringImage = senderVC.imageNames {
let imageRef = storage.reference(forURL: "gs://gsignme-14416.appspot.com/images/\(stringImage)")
imageRef.data(withMaxSize: 25 * 1024 * 1024, completion: { (data, error) -> Void in
if error == nil {
self.SwapBook.image = UIImage(data: data!)
}else {
print("Error downloading image:" )
}
})
}
}
}
}
However, when I unwind segue no data is being passed. I put a print statement in the override func
but the print statement doesn't print and so I don't know why override func
isn't being called, I don't know what I am doing wrong.