首页 > 解决方案 > Segue 与 pass 数据工作两次

问题描述

我遇到了一个愚蠢的错误。当我运行应用程序时,我的 segue 工作了两次。我有一个包含很多部分和行的 tableview,当用户单击一行时,我想执行 segue 并以编程方式更改目标视图中的文本视图。当我运行程序并单击 tableview 时,segue 会工作两次。有什么问题?

这是我的segue代码:

override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
        print("section: \(indexPath.section)")
        categoriacliccata = indexPath.section
        print("row: \(indexPath.row)")
        rowCliccata = indexPath.row
        performSegue(withIdentifier: "segue_testo", sender: self)
    }

    override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
        if (segue.identifier == "segue_testo") {
            let secondVC: TextView_Controller = segue.destination as! TextView_Controller
            secondVC.recivedCategoria = categoriacliccata
            secondVC.recivedRow = rowCliccata
        }
    }

在此处输入图像描述

标签: iosarraysswifttableviewsegue

解决方案


从 VC 本身而不是从单元中进行转场,因为从单元中运行在 IB 中链接的代码和您在其中编写的代码didSelectRow


推荐阅读