我从表视图控制器移动到视图控制器以显示有关所选特定单元格的信息时遇到问题。

override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
    if segue.identifier == "SentDetailView" {
        let indexPath: NSIndexPath = self.tableView.indexPathForSelectedRow! as NSIndexPath
        let referrals = referralsSent[indexPath.row]

        let destViewController = segue.destination as! SentDetailViewController
        destViewController.referringTo = referrals.referTo
        destViewController.patientsName = referrals.patientsName
        //print("Contained value during segue " + destViewController.patientsName!)
        destViewController.patientsPhoneNumber = referrals.patientsNumber
        destViewController.patientsEmail = referrals.patientsEmail
        destViewController.comments = referrals.comment
    }
}


故事板设置:



我得到以下结果:



我选择一个单元格,它只是突出显示而没有执行任何操作。

最佳答案

您应该覆盖didSelectRowAt,并使用发件人作为选定的索引路径来调用performSegue。尝试这个。

override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
    self.performSegue(withIdentifier: "SentDetailView", sender: indexPath)
}


还有这个。

override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
    if segue.identifier == "SentDetailView"{
        let indexPath = sender as! IndexPath
        let referrals = referralsSent[indexPath.row]

        let destViewController = segue.destination as! SentDetailViewController
        destViewController.referringTo = referrals.referTo
        destViewController.patientsName = referrals.patientsName
        //print("Contained value during segue " + destViewController.patientsName!)
        destViewController.patientsPhoneNumber = referrals.patientsNumber
        destViewController.patientsEmail = referrals.patientsEmail
        destViewController.comments = referrals.comment
    }
}

08-26 13:54