Swift,将数据从动态单元格行选择传递到弹出视图控制器

Swift, pass data from dynamic cell row selection to popover view controller

我的问题是是否可以将数据从选定的table视图单元格传递到其他视图控制器

第一个控制器中的 table 视图使用原型单元

第二个视图控制器有 3 个其他标签,如此处所示

我尝试了此处描述的方法: but it didn't work and gave me the error "Placeholder for UIStoryboardPopoverPresentationSegueTemplate" which I understand from reading this old thread top answer 那是因为我使用的是原型单元及其动态

我想要的是,每次用户选择一行时,第二个视图控制器就会充满这个关系

字符串 1 → 字符串 4

字符串 2 → 字符串 5

字符串 3 → 字符串 6

到目前为止,我已经尝试了一些方法,例如:

     func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
            tableView.deselectRow(at: indexPath, animated: true)
            let vc = storyboard?.instantiateViewController(identifier:  "secondVC") as! CalculadoraViewController
            present(vc, animated: true)
            let string4 = string4array[indexPath[1]]
            performSegue(withIdentifier: "secVC", sender: string4)            
    }
    override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
        if let vc = segue.destination as? CalculadoraViewController {
            vc.string4.text = (sender as! String)
        }
    }

弹出视图控制器代码:

class CalculadoraViewController: UIViewController {

    @IBOutlet weak var string4: UILabel!
    @IBOutlet weak var string5: UILabel!

    override func viewDidLoad() {
        super.viewDidLoad()
    }
}

如果您要呈现 View-Controller:

,则无需执行 segue
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
    let vc = storyboard?.instantiateViewController(identifier: "secondVC") as! CalculadoraViewController
    vc.string4.text = string4array[indexPath.row]
    present(vc, animated: true)         
}

这是你传递数据的方式

class CalculadoraViewController: UIViewController {

    @IBOutlet weak var montoUSD: UITextField!
    @IBOutlet weak var montoCRC: UITextField!
    @IBOutlet weak var prVenta: UILabel!
    @IBOutlet weak var prCompra: UILabel!
    var prVentaText:String!
    var prCompraText:String!


    override func viewDidLoad() {

        prVenta.text = prVentaText
        prCompra.text = prCompraText


        montoUSD.placeholder = montoCRC.text
        super.viewDidLoad()
    }
}


   func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
        tableView.deselectRow(at: indexPath, animated: true)
        let vc = storyboard?.instantiateViewController(identifier:  "calculadora") as! CalculadoraViewController

        vc.prCompraText = String(precioCompra[indexPath.row])
        vc.prVentaText =  String(precioVenta[indexPath.row])

    present(vc, animated: true)

}