我试图通过unwind segue传递信息。我有一个自定义表视图,然后我点击它,它将segue展开到上一个segue。
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
let indexPath = self.selectedIndex
self.performSegue(withIdentifier: "SwapBack", sender: indexPath)
}
但是当我解开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?")
}
}
在目的地segue。这是启动展开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:" )
}
})
}
}
}
}
然而,当我解开segue时,没有传递任何数据。我在override func
中放了一个print语句,但print语句没有打印,所以我不知道为什么override func
没有被调用,我不知道我做错了什么。