我有我的代码的以下部分,我正在尝试解决这些问题,以便从表视图控制器移动到视图控制器。
override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath){
let donation = donations[indexPath.row]
print(donation)
self.performSegue(withIdentifier: "showDonationReviewForm", sender: Any?)
}
在上面,当我打印时donation
,它会正确打印对象及其相关字段。我知道在某些时候我需要使用,override func prepare(for segue...
但我不知道如何将捐赠对象传递给下一个控制器。
你可以试试
performSegue(withIdentifier: "showDonationReviewForm", sender:donations[indexPath.row])
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
if segue.identifier == "showDonationReviewForm" {
if let nextViewController = segue.destination as? NextViewController {
nextViewController.toSend = sender as! Donation
}
}
}
class NextViewController :UIViewController {
var toSend:Donation?
....
}
假设donations
是一个Donation
模型数组
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句